home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 119.6 KB | 3,982 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UWindow.cp
- // Copyright © 1987-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // MacApp
-
- #ifndef __UADORNERS__
- #include "UAdorners.h"
- #endif
-
- #ifndef __UCOREERRORMGR__
- #include "UCoreErrorMgr.h"
- #endif
-
- #ifndef __UCOREGLOBALS__
- #include "UCoreGlobals.h"
- #endif
-
- #ifndef __UCOREUTILITIES__
- #include "UCoreUtilities.h"
- #endif
-
- #ifndef __UCONTAINER__
- #include "UContainer.h"
- #endif
-
- #ifndef __UDEBUG__
- #include "UDebug.h"
- #endif
-
- #ifndef __UDESIGNATOR__
- #include "UDesignator.h"
- #endif
-
- #ifndef __UDIALOGBEHAVIOR__
- #include "UDialogBehavior.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #ifndef __UDOCUMENT__
- #include "UDocument.h"
- #endif
-
- #if qDrag
- #ifndef __UDRAGDROP__
- #include "UDragDrop.h"
- #endif
-
- #endif
-
- #if qDrag
- #ifndef __UDRAGDROPBEHAVIOR__
- #include "UDragDropBehavior.h"
- #endif
-
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UFILE__
- #include "UFile.h"
- #endif
-
- #ifndef __FLOATWINDOW__
- #include "FloatWindow.h"
- #endif
-
- #if qDrag
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UPRINTHANDLER__
- #include "UPrintHandler.h"
- #endif
-
- #ifndef __USCRIPTING__
- #include "UScripting.h"
- #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- // Toolbox
-
- #ifndef __AEREGISTRY__
- #include <AERegistry.h>
- #endif
-
- #ifndef __FIXMATH__
- #include <FixMath.h>
- #endif
-
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- //CALib
- #if qContainer
- #ifndef _CALIB_
- #include "CALib.h"
- #endif
-
- #endif
-
- enum
- {
- kActivateWindow = TRUE, kDeactivateWindow = FALSE
- };
-
- //========================================================================================
- // static data members
- //========================================================================================
- short TWindow::gStandardWindowStaggerCount;
-
- Boolean TWindow::pInBeginUpdate;
- GrafPtr TWindow::pInBeginUpdateWindowPtr;
- RgnHandle TWindow::pSavedUpdateRegion;
- RgnHandle TWindow::pSavedVisRegion;
- CPoint TWindow::pSavedVisRegionOriginalOffset;
- TDynamicArray* TWindow::gWindows;
-
- //========================================================================================
- // CLASS TCloseWindowCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TServerCommand
-
- #pragma segment MASelCommand
- MA_DEFINE_CLASS_M1(TCloseWindowCommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TCloseWindowCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- TCloseWindowCommand::TCloseWindowCommand() :
- fWindow(NULL),
- fMessage(NULL),
- fReply(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TCloseWindowCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TCloseWindowCommand::~TCloseWindowCommand()
- {
- // NOTE: We deliberately do not dispose of fMessage and fReply.
- }
-
- //----------------------------------------------------------------------------------------
- // TCloseWindowCommand::ICloseWindowCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TCloseWindowCommand::ICloseWindowCommand(CommandNumber itsCommandNumber,
- TWindow* itsWindow)
- {
- TCommandHandler * aContext = itsWindow->GetCommandContext(itsCommandNumber);
-
- ICommand(itsCommandNumber, aContext, kCantUndo, kDoesNotCauseChange, NULL);
-
- fWindow = itsWindow;
-
- // // If this command is to notify another command then do a link.
- // if (linkedCommand)
- // LinkToSecondary(linkedCommand);
-
- #if qDebug
- // We should never get a window which has a document attached because we
- // intercept that situation in TWindow's CloseByUser and DoAEClose.
- if (fWindow->fDocument != NULL && fWindow->fClosesDocument)
- ProgramBreak("Attempt to close window which has a document");
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // TCloseWindowCommand::ICloseWindowCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TCloseWindowCommand::ICloseWindowCommand(TWindow* itsWindow,
- TAppleEvent* message,
- TAppleEvent* reply)
- {
- TCommandHandler * aContext = itsWindow->GetCommandContext(cClose);
- ICommand(cClose, aContext, kCantUndo, kDoesNotCauseChange, NULL);
-
- fWindow = itsWindow;
- fMessage = message;
- fReply = reply;
-
- // // If this command is to notify another command then do a link.
- // if (linkedCommand)
- // LinkToSecondary(linkedCommand);
-
- #if qDebug
- // We should never get a window which has a document attached because we
- // intercept that situation in TWindow's CloseByUser and DoAEClose.
- if (fWindow->fDocument != NULL && fWindow->fClosesDocument)
- ProgramBreak("Attempt to close window which has a document");
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // TCloseWindowCommand::MakeAppleEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- TAppleEvent* TCloseWindowCommand::MakeAppleEvent()
- {
- MAVolatileInit(TAppleEvent * , mayFailEvent, NULL);
- CTempDesc theWindowDesc;
-
- FailInfo fi;
- Try(fi)
- {
- TAppleEvent * theEvent = new TAppleEvent;
- theEvent->IAppleEvent(kAECoreSuite, kAEClose, gServerAddress, kAEWaitReply);
- mayFailEvent = theEvent;
-
- fWindow->MakeObjectSpecifier(theWindowDesc, fWindow->GetSpecifierForm());
- theEvent->WriteParameter(keyDirectObject, theWindowDesc);
-
- // We don't save any of the saving options here because that is done
- // in the TCloseDocument command.
-
- fi.Success();
- }
- else // Recover
- {
- mayFailEvent = (TAppleEvent *)FreeIfObject(mayFailEvent);
- fi.ReSignal();
- }
-
- return mayFailEvent;
- }
-
- //----------------------------------------------------------------------------------------
- // TCloseWindowCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TCloseWindowCommand::DoIt()
- {
- if (fWindow)
- {
- // FailInfo fi;
- // Try(fi)
- // {
- fWindow->CloseAndFree();
- // fi.Success();
- // }
- // else
- // {
- // SetValidationError(fi.error); // In case we are linked.
- // fi.ReSignal();
- // }
- }
- }
-
-
- //========================================================================================
- // CLASS TWindow
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M2(TWindow,
- Inherited,
- MScriptableObject);
-
- //----------------------------------------------------------------------------------------
- // TWindow Constructor.
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- TWindow::TWindow() :
- MScriptableObject(cWindow),
-
- // We can't tell if any changing will be required so we just the fMustxxx these false here. If
- // the developer sets them true then we respect them or if the developer calls the
- // corresponding functions we set them.
- fMoveBounds(gZeroRect), // gZeroRect indicates dynamic (the default)
- fResizeLimits(gZeroRect), // gZeroRect indicates dynamic (the default)
- fContentDifference(gZeroPt),
- fContentRegionInset(gZeroPt),
- fScriptingPrintHandler(NULL),
- fTarget(this),
- fWMgrWindow(NULL),
- fTargetID(fIdentifier),
- fProcID(0),
- fPreDocname(0),
- fConstTitle(0),
- fStrListID(kNoResource), // window's title: STR# rsrc id
- fIndex(kNoResource), // index into STR#
- fUpdating(FALSE),
- fIsActive(FALSE),
- fIsResizable(TRUE),
- fIsClosable(TRUE),
- fFreeOnClosing(FALSE),
- fDisposeOnFree(TRUE),
- fClosesDocument(TRUE),
- fOpenInitially(TRUE),
- fDoFirstClick(FALSE),
- fFloats(FALSE),
- fHideOnSuspend(FALSE),
- fWasHiddenOnSuspend(FALSE),
- fGenerateActivates(TRUE),
-
- fMustAdapt(FALSE),
- fMustHorzCenter(FALSE),
- fMustVertCenter(FALSE),
- fMustStagger(FALSE),
- fMustForceOnScreen(FALSE),
-
- fAdapted(FALSE), // Set by AdaptToScreen
- fHorzCentered(FALSE), // Set by Center
- fVertCentered(FALSE), // Set by Center
- fStaggered(FALSE), // Set by SimpleStagger
- fForcedOnScreen(FALSE) // Set by ForceOnScreen
-
- #if qDrag
- ,
- fDroppableViewList(NULL), // Drag and Drop data
- fDropStatusCache(NULL),
- fDragCallbackStatus(eWindowNotInited)
- #endif // qDrag
-
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::IWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TWindow::IWindow(TDocument* itsDocument,
- WindowRef itsWMgrWindow,
- Boolean canResize,
- Boolean canClose,
- Boolean disposeOnFree)
- {
- #if qDebug
- if (!itsWMgrWindow)
- {
- #if qDebugMsg
- ProgramBreak("TWindow::IWindow requires a valid WindowRef!");
- #endif
-
- Free();
- Failure(minErr, 0);
- }
- #endif
-
- MAVolatileInit(WindowRef, volatileItsWMgrWindow, itsWMgrWindow);
- MAVolatileInit(Boolean, volatileDisposeOnFree, disposeOnFree);
-
- //MAVolatile(GrafPtr, savePort);
- GrafPtr savePort; // can't be volatile because it is passed by reference
- GetPort(&savePort);
-
- CPoint itsLocation = ((CRect &)GetWindowPort(volatileItsWMgrWindow)->portRect)[topLeft];
- SetPortWindowPort(volatileItsWMgrWindow); // So LocalToGlobal works
- LocalToGlobal(&itsLocation);
-
- VPoint portSize(((CRect &)GetWindowPort(volatileItsWMgrWindow)->portRect).GetSize());
- FailInfo fi1;
- Try(fi1)
- {
- IView(itsDocument, NULL, itsLocation, portSize, sizeVariable, sizeVariable);
- fi1.Success();
- }
- else // Recover
- {
- SetPort(savePort);
- volatileItsWMgrWindow = FreeIfWMgrWindow(volatileItsWMgrWindow, volatileDisposeOnFree);
- fi1.ReSignal();
- }
-
- // Initialize instance variables.
- fWMgrWindow = volatileItsWMgrWindow;
- fDisposeOnFree = volatileDisposeOnFree;
-
- ResNumber itsID = 0;
- Handle theWDEFProc = WindowPeek(volatileItsWMgrWindow)->windowDefProc;
- if (IsAResource(theWDEFProc))
- {
- ResType itsType;
- CStr255 itsName;
-
- GetResInfo(theWDEFProc, &itsID, &itsType, itsName);
- }
- fProcID = (itsID << 4) | GetWindowVariant(fWMgrWindow);
-
- fIsResizable = canResize;
-
- FailInfo fi2;
- Try(fi2)
- {
- if (canResize)
- AddAdorner(gResizeIconAdorner, kAdornLast, FALSE);
- fIsClosable = canClose;
- BuildWindowRegions(BuildWindowRegions(kBuild));// sets fContentRegionInset && fContentDifference
-
- // don't use the GetResizeLimits accessor b/c we want to preserve zero values for dynamics
- SetResizeLimits(fResizeLimits[topLeft], fResizeLimits[botRight]);
-
- CStr255 aString;
- GetTitle(aString);
-
- short preDocname;
- short constTitle;
- if (ParseTitleTemplate(aString, preDocname, constTitle))
- SetWTitle(fWMgrWindow, aString);
- fPreDocname = preDocname;
- fConstTitle = constTitle;
-
- if (itsDocument)
- {
- itsDocument->GetTitle(aString);
- if (!aString.IsEmpty()) // not an untitled document
- SetTitleForDoc(aString);
- }
-
- AddAdorner(gEraseAdorner, kAdornFirst, FALSE);
-
- RegisterWindow(this); // add to the lookup table
-
- fi2.Success();
- }
- else // Recover
- {
- SetPort(savePort);
- Free();
- fi2.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- TObject* TWindow::Clone() // override
- {
- MAVolatileInit(TWindow * , aClonedWindow, (TWindow *)Inherited::Clone());
-
- if (aClonedWindow->fWMgrWindow != NULL)
- {
- MAVolatileInit(Boolean, oldPerm, PermAllocation(FALSE));
-
- aClonedWindow->fWMgrWindow = NULL;
-
- FailInfo fi;
- Try(fi)
- {
- CRect boundsRect(GetWindowPort(fWMgrWindow)->portRect);
-
- WindowRef behind;
- if (IsModal())
- behind = (WindowRef) - 1;
- else
- behind = GetBehindWindowPtr();
-
- CStr255 windowTitle;
- GetTitle(windowTitle);
-
- long windowRefCon = GetWRefCon(fWMgrWindow);
-
- WindowRef aWMgrWindow;
- if (qNeedsColorQD || HasColorQD())
- {
- WindowRef storage = NULL;
- #if !STRICT_WINDOWS
- storage = (WindowRef)new CWindowRecord;
- #endif
-
- aWMgrWindow = NewCWindow(storage, &boundsRect, windowTitle, FALSE, fProcID, behind, fIsClosable, windowRefCon);
- }
- else
- {
- WindowRef storage = NULL;
- #if !STRICT_WINDOWS
- storage = (WindowRef)new WindowRecord;
- #endif
-
- aWMgrWindow = NewWindow(storage, &boundsRect, windowTitle, FALSE, fProcID, behind, fIsClosable, windowRefCon);
- }
- aClonedWindow->fWMgrWindow = aWMgrWindow;
- FailNIL(aWMgrWindow);
-
- oldPerm = PermAllocation(oldPerm);
- fi.Success();
- }
- else
- {
- aClonedWindow->Free();
- oldPerm = PermAllocation(oldPerm);
- fi.ReSignal();
- }
- }
-
- return aClonedWindow;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TWindow::DoPostCreate(TDocument* itsDocument)// Override
- {
- Inherited::DoPostCreate(itsDocument);
-
- // don't use the GetResizeLimits accessor b/c we want to preserve zero values for dynamics
- SetResizeLimits(fResizeLimits[topLeft], fResizeLimits[botRight]);
- BuildWindowRegions(BuildWindowRegions(kBuild));// sets fContentRegionInset && fContentDifference
-
- #if qDrag
- fDragCallbackStatus = eNotInstalled;
-
- if (HasDragManager() && fDroppableViewList &&// If subviews have registered
- !fDroppableViewList->IsEmpty()) // then register the window with the drag session
- {
- TDragDropSession::fgDragDropSession->RegisterDroppableWindow(this, fWMgrWindow);
- fDragCallbackStatus = eInstalled;
- }
- #endif // qDrag
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetBehindWindowPtr:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- WindowRef TWindow::GetBehindWindowPtr()
- {
- WindowRef behind = GetLastFloatingWindowPtr();
- if (!behind)
- behind = (WindowRef)(-1); // bring the window up in front of all other windows
-
- return behind;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetDialogBehavior:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- TDialogBehavior* TWindow::GetDialogBehavior()
- {
- return (TDialogBehavior *)GetBehaviorWithIdentifier(kDialogBehavior);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::SetModality:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TWindow::SetModality(Boolean modal)
- {
- TDialogBehavior * itsDialogBehavior = GetDialogBehavior();
-
- if (itsDialogBehavior)
- itsDialogBehavior->fModal = modal;
- else
- {
- if (modal)
- {
- // Allocate the behavior from temporary memory in case we are trying to warn
- // the user about something. We shouldn't fail here.
- Boolean oldObjectPerm = AllocateObjectsFromPerm(FALSE);
- itsDialogBehavior = new TDialogBehavior;
- AllocateObjectsFromPerm(oldObjectPerm);
- itsDialogBehavior->IDialogBehavior(modal, kNoIdentifier, kNoIdentifier);
- AddBehavior(itsDialogBehavior);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::SetDialogItems:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TWindow::SetDialogItems(IDType itsDefaultItem,
- IDType itsCancelItem)
- {
- TDialogBehavior * itsDialogBehavior = GetDialogBehavior();
-
- if (itsDialogBehavior)
- {
- itsDialogBehavior->fDefaultItem = itsDefaultItem;
- itsDialogBehavior->fCancelItem = itsCancelItem;
- }
- else
- {
- if ((itsDefaultItem != kNoIdentifier) || (itsCancelItem != kNoIdentifier))
- {
- // Allocate the behavior from temporary memory in case we are trying to warn
- // the user about something. We shouldn't fail here.
- Boolean oldObjectPerm = AllocateObjectsFromPerm(FALSE);
- itsDialogBehavior = new TDialogBehavior;
- AllocateObjectsFromPerm(oldObjectPerm);
- itsDialogBehavior->IDialogBehavior(FALSE, itsDefaultItem, itsCancelItem);
- AddBehavior(itsDialogBehavior);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- TWindow::~TWindow()
- {
- Boolean disposeOnFree = fDisposeOnFree;
- WindowRef wmgrWindow = fWMgrWindow;
-
- #if qDrag
- if (HasDragManager() && fDragCallbackStatus == eInstalled)// remove drag manager callbacks
- {
- TDragDropSession::fgDragDropSession->UnregisterDroppableWindow(fWMgrWindow);
- fDragCallbackStatus = eNotInstalled;
- }
-
- fDroppableViewList = (TList *)FreeIfObject(fDroppableViewList);
- fDropStatusCache = (TDynamicArray *)FreeIfObject(fDropStatusCache);
- #endif // qDrag
-
- DeleteWindow(this); // remove from the lookup table
- fWMgrWindow = NULL;
- BeInPort(NULL); // make sure subviews don't depend on the window manager window
-
- if (fDocument)
- fDocument->DeleteWindow(this);
- else
- gDispatcher->DeleteWindow(this);
-
- wmgrWindow = FreeIfWMgrWindow(wmgrWindow, disposeOnFree);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- IDType TWindow::GetStandardSignature() // override
- {
- return kStdWindow;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TWindow::ReadFields(TStream* aStream) // override
- {
- Inherited::ReadFields(aStream);
-
- WindowFlags itsFlags;
-
- FailInfo fi;
- Try(fi)
- {
- CStr255 title;
- VRect bounds(GetFrame());
-
- fProcID = aStream->ReadInteger();
-
- fTargetID = aStream->ReadIDType();
-
- aStream->ReadBytes(&itsFlags, sizeof(WindowFlags));
-
- fStrListID = aStream->ReadInteger();
- fIndex = aStream->ReadInteger();
- if (fStrListID != kNoResource) // retrieve the window's title from the resource
- GetIndString(title, fStrListID, fIndex);
-
- WindowRef behind;
- if (IsModal())
- behind = (WindowRef) - 1;
- else
- behind = GetBehindWindowPtr();
-
- // Compatibility Floating WDEF support. We will
- // use the WDEF specified by this ID if we are not
- // running on System 7.5 or better. If we are, however,
- // we will change the ID dynamically in the window
- // initialization sequence. This ensures that we use
- // the WDEF stored in your program on pre System 7.5
- // but, use the WDEF stored in the system thereafter.
-
- // top 12 bits identify the WDEF, bottom 4 bits are the style
- short procID = fProcID; // default
- if (qNeedsSystem7_5 || GetSystemVersion() >= 0x750)
- if ((fProcID & 0xFFF0) == kSystem75AndLess_kWindoidWDEF)
- procID = kSystem75_kWindoidWDEF | (fProcID & 0x000F);
-
- WindowRef aWMgrWindow;
- CRect theBounds = bounds.ToRect();
- if (qNeedsColorQD || HasColorQD())
- aWMgrWindow = (WindowRef)NewCWindow(NULL, &theBounds, title, FALSE, procID, behind, itsFlags.GetHasGoAway(), ((long)this));
- else
- aWMgrWindow = NewWindow(NULL, &theBounds, title, FALSE, procID, behind, itsFlags.GetHasGoAway(), ((long)this));
- fWMgrWindow = aWMgrWindow;
-
- fIsResizable = itsFlags.GetResizable();
- fIsClosable = itsFlags.GetHasGoAway();
- fDoFirstClick = itsFlags.GetDoFirstClick();
- fFreeOnClosing = itsFlags.GetFreeOnClosing();
- fDisposeOnFree = itsFlags.GetDisposeOnFree();
- fClosesDocument = itsFlags.GetClosesDocument();
- fOpenInitially = itsFlags.GetOpenInitially();
-
- GetTitle(title);
-
- short preDocname;
- short constTitle;
- if (ParseTitleTemplate(title, preDocname, constTitle))
- SetWTitle(fWMgrWindow, title);
- fPreDocname = preDocname;
- fConstTitle = constTitle;
-
- RegisterWindow(this); // add to the lookup table
-
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
-
- fMustAdapt = itsFlags.GetMustAdaptToScreen();
- fMustStagger = itsFlags.GetStagger();
- fMustForceOnScreen = itsFlags.GetMustForceOnScreen();
- fMustHorzCenter = itsFlags.GetHorzCenter();
- fMustVertCenter = itsFlags.GetVertCenter();
- fFloats = itsFlags.GetFloats();
-
- fHideOnSuspend = itsFlags.GetHideOnSuspend();
- fGenerateActivates = itsFlags.GetGenerateActivates();
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- void TWindow::WriteFields(TStream* aStream) // override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteInteger(fProcID);
- aStream->WriteIDType(fTargetID);
-
- WindowFlags itsFlags;
-
- itsFlags.Initialize();
- itsFlags.SetHasGoAway(fIsClosable);
- itsFlags.SetResizable(fIsResizable);
- itsFlags.SetDoFirstClick(fDoFirstClick);
- itsFlags.SetFreeOnClosing(fFreeOnClosing);
- itsFlags.SetDisposeOnFree(fDisposeOnFree);
- itsFlags.SetClosesDocument(fClosesDocument);
- itsFlags.SetOpenInitially(fOpenInitially);
- itsFlags.SetMustAdaptToScreen(fMustAdapt);
- itsFlags.SetStagger(fMustStagger);
- itsFlags.SetMustForceOnScreen(fMustForceOnScreen);
- itsFlags.SetVertCenter(fMustVertCenter);
- itsFlags.SetHorzCenter(fMustHorzCenter);
- itsFlags.SetFloats(fFloats);
- itsFlags.SetHideOnSuspend(fHideOnSuspend);
- itsFlags.SetGenerateActivates(fGenerateActivates);
-
- // write the flags
- aStream->WriteBytes(&itsFlags, sizeof(WindowFlags));
-
- // write the window title
- aStream->WriteInteger(fStrListID);
- aStream->WriteInteger(fIndex);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::Activate:
- //----------------------------------------------------------------------------------------
- #pragma segment MAActivate
-
- void TWindow::Activate(Boolean entering)
- {
- Boolean different = (entering != IsActive());
- if (different)
- {
- // Change to allow floating windows to be activated even if there is an
- // active document window around.
- if (entering && !fFloats)
- {
- // make sure that there is not already an active window - we
- // can't have two active ones at the same time (note that code outside
- // MacApp might call SelectWindow and generate activate events for windows
- // that really are not active, so we have to catch this possibility)…
- CWMgrIterator iter;
- TWindow * theMAWindow = NULL;
-
- for (WindowRef aWindowPtr = iter.FirstWMgrWindow(); iter.More(); aWindowPtr = iter.NextWMgrWindow())
- {
- if ((theMAWindow = WMgrToWindow(aWindowPtr)) != NULL)
- if (theMAWindow->IsActive() && !IsFloatWindow(aWindowPtr))
- return; // someone else is active - bail out!
- }
- }
-
- Inherited::Activate(entering);
-
- fIsActive = entering;
-
- #if FALSE
- // The following block implements a new style of target management for
- // floating window support that was (temporarily) introduced for MacApp 3.1.
- // Because of the reaction from MacApp developers, we have reverted to
- // MacApp 3.0.1's style of handling activation. This block has been left in
- // the MacApp source because the jury is still out on how best to handle
- // the situation where a floater wants to be the target…
-
- TWindow * windowOfTarget = NULL;
- if (gDispatcher->GetTarget() != NULL)
- windowOfTarget = gDispatcher->GetTarget()->GetWindow();
- Boolean targetInFloatingWindow = windowOfTarget != NULL && windowOfTarget->fFloats;
-
- // if the target is in a floating window, leave it alone!
- if (!targetInFloatingWindow)
- if (entering)
- gDispatcher->SetTarget(fTarget);
- else
- gDispatcher->SetTarget(gDispatcher);
- #endif
-
- // The original, MacApp 3.0.1 technique:
- if (!(fFloats && (fTarget == this)))
- if (entering)
- gDispatcher->SetTarget(fTarget);
- else
- gDispatcher->SetTarget(gDispatcher);
-
- // When we de/activate a window, we need to invalidate the menus manually here.
- // Because we no longer receive activate/deactivates regularly from the Event
- // Manager, we cannot count on TApplication::DidEvent to handle this for us…
- InvalidateMenus();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::AdaptToScreen:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TWindow::AdaptToScreen()
- {
- long stdHScreen = 512; // make these longs for Long2Fix call
- long stdVScreen = 342;
-
- fAdapted = TRUE; // We adapted to the screen
-
- // Compute pixel difference between current screen and std Mac screen Note:
- // Calculation written as two separate expressions so that CPoint's "-" operator can
- // be inline.
- VPoint diff(((CRect &)qd.screenBits.bounds).GetSize());
- diff -= VPoint(stdHScreen, stdVScreen);
-
- VRect theFrame(GetFrame());
-
- // If screen is larger, enlarge the window. If the window is too large, shrink it
- if (diff != gZeroVPt || !((CRect &)qd.screenBits.bounds).Contains(theFrame[botRight].ToPoint()))
- {
- // do an adjustment for larger screen
- // the window adapted to the new screen size by proportion.
- VPoint newSize(Fix2Long(FixMul(Long2Fix(fSize.h), FixDiv(Long2Fix(stdHScreen + diff.h), Long2Fix(stdHScreen)))), Fix2Long(FixMul(Long2Fix(fSize.v), FixDiv(Long2Fix(stdVScreen + diff.v), Long2Fix(stdVScreen)))));
-
- // Consider the location of the window, bound it by the resize limits
- CRect resizeLimits;
- GetDynamicResizeLimits(resizeLimits);
-
- newSize.ConstrainTo(resizeLimits);
- Resize(newSize, kInvalidate);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::AllowsMenuAccess:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::AllowsMenuAccess()
- {
- // Default is to always allow menu access, even if modal
- return TRUE;
- }
-
-
- typedef WindowDefProcPtr* WDefProcTypeHandle;
-
- //----------------------------------------------------------------------------------------
- // TWindow::Center:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TWindow::Center(Boolean horizontally,
- Boolean vertically,
- Boolean forDialog)
- {
- if (fWMgrWindow)
- {
- fHorzCentered = horizontally;
- fVertCentered = vertically;
-
- Boolean rgnsWereBuilt = BuildWindowRegions(kBuild);
- CTemporaryRegion strucRgn;
- GetWindowStructureRgn(fWMgrWindow, strucRgn);
- CPoint windowSize(((CRect &)(*strucRgn)->rgnBBox).GetSize());
- BuildWindowRegions(rgnsWereBuilt);
-
- VRect theFrame(GetFrame());
-
- // GetMaxIntersectedDevice accounts for menubar so don't subtract GetMBarHeight
- CRect screenRect;
- GetMaxIntersectedDevice(screenRect);
- CPoint screenSize = screenRect.GetSize();
-
- if (horizontally)
- theFrame.left = screenRect.left + fContentRegionInset.h + (screenSize.h - windowSize.h) / 2;
-
- if (vertically)
- {
- if (forDialog)
- // Put it in the top third of the screen
- theFrame.top = screenRect.top + fContentRegionInset.v + (screenSize.v - windowSize.v) / 3;
- else
- theFrame.top = screenRect.top + fContentRegionInset.v + (screenSize.v - windowSize.v) / 2;
- }
-
- Locate(theFrame[topLeft], kDontInvalidate);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::Close:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TWindow::Close() // override
- {
- Inherited::Close();
-
- Show(FALSE, kRedraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::CloseAndFree:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TWindow::CloseAndFree()
- {
- Close();
- if (fFreeOnClosing)
- Free();
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::CloseByUser:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TWindow::CloseByUser(CommandNumber aCommandNumber)
- {
- // First see if the document is to be closed.
- if (fDocument)
- {
- // Allow the document to determine the proper response to
- // closing one of its windows.
- fDocument->CloseWindow(this);
- }
- else
- {
- // Close the window directly since it wasn't attached to a document.
- DoClose(aCommandNumber);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::DoClose:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
- void TWindow::DoClose(CommandNumber aCommand,
- Boolean useAppleEvent)
- {
- // Close the window if it wasn't attached to a document.
- Boolean oldTempAlloc = TemporaryAllocation(TRUE);
- Boolean oldObjectPerm = AllocateObjectsFromPerm(FALSE);
- TCloseWindowCommand * aCloseWindowCommand = new TCloseWindowCommand;
- aCloseWindowCommand->ICloseWindowCommand(aCommand, this);
- aCloseWindowCommand->fUseAppleEvent = useAppleEvent;
-
- if (useAppleEvent)
- PostCommand(aCloseWindowCommand);
- else
- aCloseWindowCommand->Process();
-
- TemporaryAllocation(oldTempAlloc);
- AllocateObjectsFromPerm(oldObjectPerm);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TWindow::DoMenuCommand(CommandNumber aCommandNumber)// override
- {
- switch (aCommandNumber)
- {
- case cClose:
- CloseByUser(aCommandNumber);
- break;
-
- default:
- Inherited::DoMenuCommand(aCommandNumber);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TWindow::DoSetupMenus() // override
- {
- if (!IsInModalState()) // Don't enable menu/app commands if modal
- {
- Enable(cClose, fIsClosable); // window objects take care of themselves!
-
- Inherited::DoSetupMenus();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::HandlesCursor:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::HandlesCursor() // override
- {
- return fHandlesCursor && (IsActive() || fDoFirstClick);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::LetsSubViewsHandleCursor:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::LetsSubViewsHandleCursor() // override
- {
- return fLetsSubViewsHandleCursor && (IsActive() || fDoFirstClick);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::HandlesHelp:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::HandlesHelp() // override
- {
- return fHandlesHelp && IsActive();
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::LetsSubViewsHandleHelp:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::LetsSubViewsHandleHelp() // override
- {
- return fLetsSubViewsHandleHelp && IsActive();
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::DrawResizeIcon:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TWindow::DrawResizeIcon()
- {
- if (fIsResizable && Focus())
- {
- CRect r(GetQDExtent());
- r[topLeft] = r[botRight] - CPoint(kSBarSizeMinus1, kSBarSizeMinus1);
-
- // clip down and avoid drawing the lines that delimit scroll bars
-
- CTemporaryRegion tempRgn;
- CTemporaryRegion tempRgn2;
-
- // Avoid drawing the GrowIcon if it would have been clipped
- GetClip(tempRgn);
- RectRgn(tempRgn2, &r);
- SectRgn(tempRgn2, tempRgn, tempRgn2);
- if (!EmptyRgn(tempRgn2))
- {
- SetClip(tempRgn2);
- PenNormal();
- DrawGrowIcon(fWMgrWindow);
- SetClip(tempRgn);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::Focus:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::Focus() // override
- {
- Boolean returnVal = FALSE;
-
- if (IsFocused()) // Already focused
- {
- #if qDebug
- GrafPtr currentPort;
-
- GetPort(¤tPort);
- if (GetGrafPort() != currentPort)
- ProgramBreak("TWindow.Focus: Port is incorrect");
- #endif
- returnVal = TRUE;
- }
- else if (fWMgrWindow) // do my own focus
- {
- // Set the port
- GrafPtr currentPort;
- GrafPtr theWindowPort = GetGrafPort();
-
- GetPort(¤tPort);
- if (currentPort != theWindowPort)
- SetPort(theWindowPort);
-
- CPoint qdOrigin(GetQDOrigin());
- SetOrigin(qdOrigin.h, qdOrigin.v);
- gFocusedView = this;
-
- // Add the clipping. Clip either to the visrgn or the update region depending on whether
- // there is an invalid area.
- RgnHandle theUpdateRgn = GetUpdateRegion(fWMgrWindow);
- if (!EmptyRgn(theUpdateRgn))
- {
- // The update region is in global coords but the clip is in local coords.
- // Offset the region to make it in local coords here and restore it there
- // to save copying it
- SuperToLocalRegion(theUpdateRgn);
- CTemporaryRegion tempRgn;
-
- if (fUpdating) // clip TO the update region
- SectRgn(GetVisRegion(theWindowPort), theUpdateRgn, tempRgn);
- else // clip OUT the update region
- DiffRgn(GetVisRegion(theWindowPort), theUpdateRgn, tempRgn);
- SetClip(tempRgn);
- LocalToSuperRegion(theUpdateRgn);
- }
- else
- SetClip(GetVisRegion(theWindowPort));
-
- returnVal = TRUE;
- }
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::FocusOnSuperView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::FocusOnSuperView() // override
- {
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetLocationAdjustment:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TWindow::GetLocationAdjustment(CPoint& delta)
- {
- const short kMinDragArea = 4;
- VRect theVFrame(GetFrame());
- CRect theFrame(theVFrame.ToRect());
-
- // since we don't _really_ know what the drag rgn is, we'll assume that moving the
- // topleft pt of the window on screen is sufficient to make it draggable, so calculate
- // the deltas necessary to move the topleft pt into visible screen CRect.
-
- CRect visScreenRect;
- GetMaxIntersectedDevice(visScreenRect); // NOTE: uses tempRgn
- visScreenRect.Inset(CPoint(kMinDragArea, kMinDragArea));
-
- if (theFrame.top < visScreenRect.top)
- delta.v = visScreenRect.top - theFrame.top + fContentRegionInset.v;
- else if (theFrame.top > visScreenRect.bottom)
- delta.v = visScreenRect.bottom - theFrame.top - fContentRegionInset.v;
-
- if (theFrame.left < visScreenRect.left)
- delta.h = visScreenRect.left - theFrame.left + fContentRegionInset.h;
- else if (theFrame.left > visScreenRect.right)
- delta.h = visScreenRect.right - theFrame.right - fContentRegionInset.h;
- }
-
-
- //----------------------------------------------------------------------------------------
- // TWindow::ForceOnScreen: ForceOnScreen guarantees that some minimal drag area is
- // accessible to the user, to be dragged to the desired location.
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TWindow::ForceOnScreen()
- {
- const short kMinDragArea = 4;
-
- fForcedOnScreen = TRUE;
-
- // On many systems (including Color QD && the Radius FPD), it's possible to have a
- // non-rectangular desktop. Try to be nice to people who saved windows on secondary
- // screens. GrayRgn is the true indicator of the shape of the
- // desktop--screenBits.bounds is the size of the screen with the menu bar on it.
-
- CTemporaryRegion tempRgn;
- CTemporaryRegion strucRgn;
- CTemporaryRegion contRgn;
-
- Boolean rgnsWereBuilt = BuildWindowRegions(kBuild);
-
- GetWindowStructureRgn(fWMgrWindow, strucRgn);
- GetWindowContentRgn(fWMgrWindow, contRgn);
- {
- DiffRgn(strucRgn, contRgn, tempRgn); // strucRgn less contRgn ≈≈ drag rgn
- if (EmptyRgn(tempRgn))
- CopyRgn(strucRgn, tempRgn); // at least get the strucRgn
- }
- BuildWindowRegions(rgnsWereBuilt);
-
- // get the desktop rgn, inset by a minimal drag area
- CTemporaryRegion aTempRgn;
-
- CopyRgn(GetGrayRgn(), aTempRgn); // aTempRgn = desktop rgn
- InsetRgn(aTempRgn, kMinDragArea, kMinDragArea);// inset aTempRgn
- SectRgn(tempRgn, aTempRgn, aTempRgn); // do drag rgn && desktop rgn instersect ?
-
- CPoint delta(gZeroPt);
-
- if (EmptyRgn(aTempRgn) || !RectInDrag((*(RgnHandle)aTempRgn)->rgnBBox))
- GetLocationAdjustment(delta); // no => adjust the window's location
-
- Locate(fLocation.ToPoint() + delta, kDontInvalidate);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetMaxIntersectedDevice:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- GDHandle TWindow::GetMaxIntersectedDevice(CRect& screenRect)
- {
- if (qNeedsColorQD || HasColorQD())
- {
- long maxSectArea = 0;
- CRect moveBounds;
- GetDynamicMoveBounds(moveBounds);
-
- // set fContentRegionInset && fContentDifference, ensure contrgn and strucrgn are available
- Boolean rgnsWereBuilt = BuildWindowRegions(kBuild);
- CTemporaryRegion strucRgn;
- GetWindowStructureRgn(fWMgrWindow, strucRgn);
- CRect globalStrucRect((*strucRgn)->rgnBBox);
- BuildWindowRegions(rgnsWereBuilt);
-
- GDHandle aGDHandle = GetDeviceList();
- GDHandle maxSectGD = GetMainDevice(); // set as best choice default
- while (aGDHandle)
- { // calc which scrn intersects largest part of window
- if (TestDeviceAttribute(aGDHandle, screenDevice) && TestDeviceAttribute(aGDHandle, screenActive))
- {
- CRect aGDScreenRect((*aGDHandle)->gdRect);
- CRect gdSectRect(globalStrucRect & aGDScreenRect);
- if (!(aGDScreenRect & moveBounds).Empty() && !gdSectRect.Empty())
- {
- long sectArea = gdSectRect.GetLength(vSel) * gdSectRect.GetLength(hSel);
- if (sectArea > maxSectArea) // do we have a new winner?
- {
- maxSectArea = sectArea;
- maxSectGD = aGDHandle;
- }
- }
- }
- aGDHandle = GetNextDevice(aGDHandle);
- }
-
- if (maxSectGD != GetMainDevice())
- screenRect = (*maxSectGD)->gdRect;
- else
- { // Account for menu bar on the main screen.
- // Don't just assume that its at the top of
- // the screen!
- CTemporaryRegion tempRgn;
- CRect gdRect = (*maxSectGD)->gdRect;
-
- RectRgn(tempRgn, &gdRect); // main screen with menubar
- SectRgn(tempRgn, GetGrayRgn(), tempRgn);// GetGrayRgn == desktop rgn w/o menubar
- screenRect = (*(RgnHandle)tempRgn)->rgnBBox;// => main screen w/o menubar
- }
- return maxSectGD;
- }
- else
- { // Account for menu bar on the main
- // screen. Don't just assume that its at
- // the top of the screen!
- CTemporaryRegion tempRgn;
-
- RectRgn(tempRgn, &(qd.screenBits.bounds));// main screen with menubar
- SectRgn(tempRgn, GetGrayRgn(), tempRgn);// GetGrayRgn == desktop rgn w/o menubar
- screenRect = (*(RgnHandle)tempRgn)->rgnBBox;// => main screen w/o menubar
- return NULL; // we only have GDHandle in CQD world
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetGrafPort:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- GrafPtr TWindow::GetGrafPort() // override
- {
- return (gPrinting || gDrawingPictScrap) ? qd.thePort : ((GrafPtr)fWMgrWindow);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetWindowTarget:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- TEventHandler* TWindow::GetWindowTarget()
- {
- return fTarget;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetTitle:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::GetTitle(CStr255& theTitle)
- {
- theTitle.Empty();
-
- if (fWMgrWindow)
- GetWTitle(fWMgrWindow, theTitle);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- TWindow* TWindow::GetWindow() const // override
- {
- return (TWindow *)this;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GoAwayByUser:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TWindow::GoAwayByUser(const VPoint& theMouse)
- {
- VPoint globalVMouse(theMouse);
-
- LocalToSuper(globalVMouse);
-
- if (fIsClosable && TrackGoAway(fWMgrWindow, globalVMouse.ToPoint()))
- CloseByUser(cClose);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::HandleMouseDown:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- Boolean TWindow::HandleMouseDown(const VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis,
- EMouseDownType /* mouseDownType */)// override
- {
- Boolean wasHandled = FALSE;
- short aPartCode;
- Boolean result = FALSE;
- EMouseDownType mouseDownType = kDragOrClick;
-
- // Find out where the mouse was pressed
- aPartCode = GetPartCode(theMouse);
-
- // Test to determine if the window should be selected. To be selected,
- // • this window must not be the active window; and
- // • this window must not float, or if it does, it must not be front-most.
- if ((gDispatcher->GetActiveWindow(kNoFloaters) != this) && (!fFloats || (fWMgrWindow != FrontWindow())))
- {
- mouseDownType = fDoFirstClick ? kFirstClick_dragOrClick : kFirstClick_dragOnly;
-
- if (aPartCode != inContent && (aPartCode != inDrag || !event->IsCommandKeyPressed()))
- {
- Select();
- gDispatcher->UpdateAllWindows();
- }
- /* if (aPartCode != inDrag || !event->IsCommandKeyPressed())*/
- /* {*/
- /* Select();*/
- /* gDispatcher->UpdateAllWindows();*/
- /* }*/
- }
-
- // dispatch according to where the mouse was pressed
- switch (aPartCode)
- {
- case inContent:
- wasHandled = Inherited::HandleMouseDown(theMouse, event, hysteresis, mouseDownType);
- #if qContainer
- //need to only do this if the document does not have the focus(NULL Check)
-
- if (gContainerLib && wasHandled) //&& (gDispatcher->fCurrentDocument == NULL)) •••••••
- {
- Boolean standardFocusAquired = CARequestStandardFocusSet(fWMgrWindow);
- FailOSErr(CAError());
- #if qDebug
- if (!standardFocusAquired)
- {
- DebugStr((StringPtr)"\pFailed to aquire the standard focus from OpenDoc.");
- }
- #endif
-
- }
- #endif
-
- break;
-
- case inDrag:
- MoveByUser(theMouse);
- wasHandled = TRUE;
- break;
-
- case inGrow:
- ResizeByUser(theMouse);
- wasHandled = TRUE;
- break;
-
- case inGoAway:
- GoAwayByUser(theMouse);
- wasHandled = TRUE;
- break;
-
- case inZoomIn:
- case inZoomOut:
- ZoomByUser(theMouse, aPartCode);
- wasHandled = TRUE;
- break;
-
- case inDesk:
- wasHandled = TRUE;
- break;
-
- default:
- break;
- }
-
- return wasHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::HasPendingUpdate:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::HasPendingUpdate()
- {
- return !EmptyRgn(GetUpdateRegion(fWMgrWindow));
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetPartCode:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- short TWindow::GetPartCode(const VPoint& theMouse)// override
- {
- short returnVal = inDesk;
-
- VPoint globalVWhere(theMouse);
-
- LocalToSuper(globalVWhere);
-
- // Call FindWindow to determine the partcode
- WindowRef aWMgrWindow;
- short partCode = FindWindow(globalVWhere.ToPoint(), &aWMgrWindow);
- if (aWMgrWindow == fWMgrWindow) // if we fail this sanity check, then
- returnVal = partCode; // passed the sanity check so return the
- // part code we got back from FindWindow
- #if qDebug
- else
- ProgramBreak("in TWindow.GetPartCode: passed a VPoint that didn't belong to the window");
- #endif
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::BeInDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TWindow::BeInDocument(TDocument* itsDocument)
- {
- CStr255 aString;
-
- Inherited::BeInDocument(itsDocument);
-
- if (fDocument && (itsDocument != fDocument))
- fDocument->DeleteWindow(this);
-
- if (itsDocument)
- {
- gDispatcher->DeleteWindow(this); // Just in case…
- itsDocument->AddWindow(this);
- itsDocument->GetTitle(aString);
- if (!aString.IsEmpty()) // not an untitled document
- SetTitleForDoc(aString);
- fNextHandler = itsDocument;
- }
- else
- {
- gDispatcher->AddWindow(this);
- fNextHandler = gDispatcher;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::IsDismissed:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- Boolean TWindow::IsDismissed()
- {
- TDialogBehavior * theDialogBehavior = GetDialogBehavior();
-
- return theDialogBehavior ? theDialogBehavior->fDismissed : TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::Dismiss:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::Dismiss(IDType dismisser,
- Boolean validate)
- {
- TDialogBehavior * theDialogBehavior = GetDialogBehavior();
-
- if (theDialogBehavior)
- theDialogBehavior->Dismiss(dismisser, validate);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::RectInDrag:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- Boolean TWindow::RectInDrag(const CRect& whichRect)
- // Returns true if any of the corner points of whichRect are draggable.
- {
- Boolean result = FALSE; // assume window isn't draggable
-
- WDefProcTypeHandle wDefProc = (WDefProcTypeHandle)GetAndLoadWDefProc(((WindowPeek)fWMgrWindow)->windowDefProc);
- if (wDefProc != NULL)
- {
- SignedByte saveState = LockHandle((Handle)wDefProc);
- WindowDefProcPtr wdef = *wDefProc;
-
- Boolean rgnsWereBuilt = BuildWindowRegions(kBuild);// regions needed for hit testing
- short variant = GetWindowVariant(fWMgrWindow);
-
- // (ZOR) The following hack is to get around a bug in Zortech. They aren't
- // correctly applying the conversion operator 'CPoint::operator long()'.
-
- CPoint leftTop(whichRect.left, whichRect.top);
- CPoint rightBottom(whichRect.right, whichRect.bottom);
- CPoint leftBottom(whichRect.left, whichRect.bottom);
- CPoint rightTop(whichRect.right, whichRect.top);
-
- result = ((CallWindowDefProc(wdef, variant, fWMgrWindow, wHit, *((long*) & leftTop)) == wInDrag)
- || (CallWindowDefProc(wdef, variant, fWMgrWindow, wHit, *((long*) & rightBottom)) == wInDrag)
- || (CallWindowDefProc(wdef, variant, fWMgrWindow, wHit, *((long*) & leftBottom)) == wInDrag)
- || (CallWindowDefProc(wdef, variant, fWMgrWindow, wHit, *((long*) & rightTop)) == wInDrag));
-
- HSetState((Handle)wDefProc, saveState); // restore state of wdefproc
- BuildWindowRegions(rgnsWereBuilt); // restore state of window rgns
- }
- #if qDebugMsg
- else
- ProgramBreak("###TWindow.RectInDrag: can't load wdef");
- #endif
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::IsHiddenOnSuspend:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- Boolean TWindow::IsHiddenOnSuspend()
- {
- return fHideOnSuspend; // clipboard windows && floaters should
- // return true (and any other window that
- // wants to get hidden when the
- // application is suspended by the Process
- // Manager).
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::IsShown:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::IsShown() // override
- {
- return fWMgrWindow ? IsWindowVisible(fWMgrWindow) : FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::IsActive:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::IsActive() // override
- {
- return fIsActive;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::DoInvalidateRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TWindow::DoInvalidateRegion(const RgnHandle badRgn)
- {
- if ((qd.thePort == (GrafPtr)GetWindowPort(fWMgrWindow)) && IsShown() && !EmptyRgn(badRgn))
- {
- ::InvalRgn(badRgn);
- if (gShowInvalidations)
- FillRgn(badRgn, &qd.ltGray);
-
- // Maintain the Focus
- if (fUpdating) // clip should INCLUDE the update region
- UnionRgn(GetClipRegion(qd.thePort), badRgn, qd.thePort->clipRgn);
- else // clip should EXCLUDE the update region
- DiffRgn(GetClipRegion(qd.thePort), badRgn, qd.thePort->clipRgn);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::DoValidateRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TWindow::DoValidateRegion(const RgnHandle goodRgn)
- {
- if ((qd.thePort == (GrafPtr)GetWindowPort(fWMgrWindow)) && IsShown())
- if (!EmptyRgn(goodRgn))
- {
- ValidRgn(goodRgn);
-
- // Maintain the Focus
- if (fUpdating) // clip should INCLUDE the update region and exclude valid bits
- DiffRgn(GetClipRegion(qd.thePort), goodRgn, qd.thePort->clipRgn);
- else // clip should EXCLUDE the update region and include valid bits
- UnionRgn(GetClipRegion(qd.thePort), goodRgn, qd.thePort->clipRgn);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::BuildWindowRegions: Calculate window size including structure region (i.e.
- // title bar). To do this we need to force the window to compute its structure region by
- // calling its defproc, if the window isn't shown. If build is false, set the regions back
- // to empty regions, so as not to confuse the window manager. Return the previous state of
- // the regions.
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- Boolean TWindow::BuildWindowRegions(Boolean build)
- {
- Boolean returnVal = kBuild;
-
- WindowRecord & theWindowRecord = *((WindowPeek)fWMgrWindow);
-
- // The regions are considered to be built if either:
- // a) the window is shown; or
- // b) the structure rgn is not empty.
-
- if (IsShown() || !EmptyRgn(theWindowRecord.strucRgn))
- {
- if ((build != kBuild) && !IsShown())
- {
- SetEmptyRgn(theWindowRecord.strucRgn);
- SetEmptyRgn(theWindowRecord.contRgn);
- }
- }
- else
- {
- if (build == kBuild)
- {
- WDefProcTypeHandle wDefProc = (WDefProcTypeHandle)GetAndLoadWDefProc(theWindowRecord.windowDefProc);
- if (wDefProc != NULL)
- {
- SignedByte saveState = LockHandle((Handle)wDefProc);
- WindowDefProcPtr wdef = *wDefProc;
- CallWindowDefProc(wdef, GetWindowVariant(fWMgrWindow), fWMgrWindow, wCalcRgns, (long)0);
-
- HSetState((Handle)wDefProc, saveState);
-
- // Calculate offset from top-left of window structure to top-left of window content
- fContentRegionInset = ((CRect &)(*theWindowRecord.contRgn)->rgnBBox)[topLeft] - ((CRect &)(*theWindowRecord.strucRgn)->rgnBBox)[topLeft];
-
- CRect globalStrucRect = (*theWindowRecord.strucRgn)->rgnBBox;
- CRect globalContRect = (*theWindowRecord.contRgn)->rgnBBox;
- fContentDifference = globalStrucRect.GetSize() - globalContRect.GetSize();
- }
- }
- returnVal = !kBuild;
- }
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::Select:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TWindow::Select()
- {
- MASelectToolboxWindow(fWMgrWindow); // 3.5
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::MoveByUser:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TWindow::MoveByUser(const VPoint& theMouse)
- {
- VPoint globalVMouse(theMouse);
-
- LocalToSuper(globalVMouse);
-
- VRect oldFrame(GetFrame());
-
- CRect moveBounds;
- GetDynamicMoveBounds(moveBounds);
- MADragWindow(fWMgrWindow, globalVMouse.ToPoint(), moveBounds);
-
- // Don't forget to tell the window object
- if (Focus())
- {
- CPoint currLoc(((CRect &)GetWindowPort(fWMgrWindow)->portRect)[topLeft]);
- LocalToGlobal(&currLoc); // can't use localtosuper since fLocation not updated yet
- Locate(currLoc, kDontInvalidate);
- }
-
- VRect newFrame(GetFrame());
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn() && (newFrame != oldFrame))
- {
- TSetPropertyEvent * theEvent = new TSetPropertyEvent;
- theEvent->ISetPropertyEvent(gServerAddress, kAENoReply + kAEDontExecute, this, pBounds);
- theEvent->WriteRect(keyAEData, newFrame.ToRect());
- TAppleEvent * theReply = theEvent->Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::Open:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TWindow::Open() // override
- {
- if (!IsShown())
- {
- // Keep us matching the window since we are parallel structures
- // Be sure all views are sized right
- Resize(((CRect &)GetWindowPort(fWMgrWindow)->portRect).GetSize(), kDontInvalidate);
-
- if (fMustAdapt && !fAdapted)
- AdaptToScreen();
- if ((fMustHorzCenter && !fHorzCentered) || (fMustVertCenter && !fVertCentered))
- Center(fMustHorzCenter, fMustVertCenter, IsModal());
-
- if (fMustStagger && !fStaggered)
- {
- // If both staggering and forcing on screen are specified then we must ensure
- // that the window is forced on screen FIRST so that the staggering will occur
- // in a visible (and usable) location. BUT, after staggering we must STILL
- // ensure that the window is forced on screen so, we reset the forced flag so
- // that forcing will occur on schedule later.
- if (fMustForceOnScreen && !fForcedOnScreen)
- {
- ForceOnScreen();
- fForcedOnScreen = FALSE; // Make sure we can be forced again
- }
- SimpleStagger(CPoint(kStdStaggerAmount, kStdStaggerAmount), gStandardWindowStaggerCount);
- }
- if (fMustForceOnScreen && !fForcedOnScreen)
- ForceOnScreen();
-
- // If fVisibleExtent is empty, InvalidateCoordinates so our contents will be drawn (b/c of caching)
- if (GetVisibleExtent().Empty())
- InvalidateCoordinates();
-
- if (fTarget)
- fTarget->SetTargetSelection(kDontRedraw);
- Show(TRUE, kRedraw); // Make me visible
-
- }
- Inherited::Open(); // Tell subviews to open in case they care
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::PoseModally:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- IDType TWindow::PoseModally()
- {
- TDialogBehavior * itsDialogBehavior = GetDialogBehavior();
- IDType result = kNoIdentifier;
-
- if (itsDialogBehavior)
- {
- Boolean wasModal = itsDialogBehavior->fModal;
-
- if (!wasModal)
- SetModality(TRUE);
-
- FailInfo fi;
- Try(fi)
- {
- Open();
- Select(); // Bring it to the front
-
- itsDialogBehavior->PoseModally();
- result = itsDialogBehavior->fDismisser;
- fi.Success();
- }
- else // Recover
- {
- CloseAndFree();
- fi.ReSignal();
- }
- if (!wasModal)
- SetModality(wasModal);
- }
- else
- {
- CloseAndFree();
- #if qDebug
- ProgramBreak("Can't PoseModally because the window doesn't contain a TDialogBehavior.");
- #endif
-
- gErrorParm3 = "TDialogBehavior"; // show name of class
- Failure(errMissingClass, 0);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::IsModal:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::IsModal()
- {
- TDialogBehavior * theDialogBehavior = GetDialogBehavior();
-
- return theDialogBehavior ? theDialogBehavior->fModal : FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::IsInModalState:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- Boolean TWindow::IsInModalState()
- {
- TDialogBehavior * theDialogBehavior = GetDialogBehavior();
-
- return theDialogBehavior ? (theDialogBehavior->fModal) && (!theDialogBehavior->fDismissed) : FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::RemovedASubView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::RemovedASubView(TView* theSubView)// override
- {
- // if theSubView (or any subView) is the target, we need to
- // set the target to this window. It might be fatal for the target to
- // point to a view no longer in the window.
-
- TEventHandler * handler;
- for (handler = gDispatcher->GetTarget(); handler != NULL; handler = handler->fNextHandler)
- {
- if (theSubView == handler)
- {
- gDispatcher->fTarget = this;
- break;
- }
- }
- for (handler = fTarget; handler != NULL; handler = handler->fNextHandler)
- {
- if (theSubView == handler)
- {
- fTarget = this;
- break;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::SetFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::SetFrame(const VRect& newFrame,
- Boolean invalidate) // override
- {
- if (fWMgrWindow)
- {
- if (!(newFrame.GetSize() < fSize))
- {
- if (newFrame[topLeft] != fLocation)
- MoveWindow(fWMgrWindow, (short)newFrame[topLeft].h, (short)newFrame[topLeft].v, FALSE);//!!! VCoordinate->short
-
- if (newFrame.GetSize() != fSize)
- SizeWindow(fWMgrWindow, (short)newFrame.GetSize().h, (short)newFrame.GetSize().v, invalidate);//!!! VCoordinate-> short
- }
- else
- {
- if (newFrame.GetSize() != fSize)
- SizeWindow(fWMgrWindow, (short)newFrame.GetSize().h, (short)newFrame.GetSize().v, invalidate);//!!! VCoordinate-> short
-
- if (newFrame[topLeft] != fLocation)
- MoveWindow(fWMgrWindow, (short)newFrame[topLeft].h, (short)newFrame[topLeft].v, FALSE);//!!! VCoordinate->short
- }
- }
-
- VPoint oldSize = fSize;
- VRect vr(-kSBarSizeMinus1, -kSBarSizeMinus1, 0, 0);// standard size of grow box
-
- if (fIsResizable && invalidate && newFrame.GetSize() != oldSize)
- InvalidateVRect(vr + fSize); // old location
-
- Inherited::SetFrame(newFrame, invalidate);
-
- if (fIsResizable && invalidate && fSize != oldSize)
- InvalidateVRect(vr + fSize); // new location
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::ResizeByUser:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::ResizeByUser(const VPoint& theMouse)
- {
- if (fIsResizable)
- {
- VPoint globalVMouse(theMouse);
-
- LocalToSuper(globalVMouse);
-
- CRect resizeLimits;
- GetDynamicResizeLimits(resizeLimits);
-
- long growResult = GrowWindow(fWMgrWindow, globalVMouse.ToPoint(), &resizeLimits);
- if (growResult)
- Resize(VPoint(LoWord(growResult), HiWord(growResult)), kInvalidate);
-
- if (growResult && TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn())
- {
- TSetPropertyEvent * theEvent = new TSetPropertyEvent;
- theEvent->ISetPropertyEvent(gServerAddress, kAENoReply + kAEDontExecute, this, pBounds);
- theEvent->WriteRect(keyAEData, GetFrame().ToRect());
- TAppleEvent * theReply = theEvent->Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::SetResizeLimits:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TWindow::SetResizeLimits(CPoint itsMinSize,
- CPoint itsMaxSize)
- {
- fResizeLimits = CRect(itsMinSize, itsMaxSize);
-
- CRect resizeLimits;
- GetDynamicResizeLimits(resizeLimits); // get the dynamic values
-
- // If the window is zoomable, keep the window's state data current
- if (GetWindowZoomFlag(fWMgrWindow))
- {
- CRect theStdState;
- GetWindowStandardState(fWMgrWindow, &theStdState);
- theStdState.right = (short)Min(theStdState.right, fLocation.h + resizeLimits.right - 1);//!!! long-> short
- theStdState.bottom = (short)Min(theStdState.bottom, fLocation.v + resizeLimits.bottom - 1);//!!! long-> short
- SetWindowStandardState(fWMgrWindow, &theStdState);
- }
-
- // If the window is not sized within the new limits, resize it to fit
- VPoint newSize(fSize);
- newSize.ConstrainTo(resizeLimits);
-
- Resize(newSize, IsVisible());
-
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TWindow::DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event) // Override
-
- {
- switch (eventNumber)
- {
- case mBecameTarget:
- if (IsActive())
- SetWindowTarget(source);
- break;
-
- default:
- Inherited::DoEvent(eventNumber, source, event);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::SetWindowTarget:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TWindow::SetWindowTarget(TEventHandler* newTarget)
- {
- if (!newTarget) // Would be annoying if a NULL got in here!
- newTarget = this;
- if (newTarget != fTarget)
- {
- fTarget->ResignedWindowTarget();
- fTarget = newTarget;
- newTarget->BecameWindowTarget();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::SetTitle:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::SetTitle(const CStr255& newTitle)
- {
- CStr255 oldTitle;
-
- GetWTitle(fWMgrWindow, oldTitle); // to minimize flash, we only set the
- // title if it's different from the
- // current title
- if (oldTitle != newTitle)
- ::SetWTitle(fWMgrWindow, newTitle);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::SetTitleForDoc:
- //----------------------------------------------------------------------------------------
- #pragma segment MAFile
-
- void TWindow::SetTitleForDoc(const CStr255& newDocTitle)
- {
- if (fPreDocname > 0) // optimize for case of nothing to do
- {
- CStr255 title;
- GetTitle(title);
-
- if (SubstituteInTitle(title, newDocTitle, fPreDocname, fConstTitle))
- SetTitle(title);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::AboutToLoseControl:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::AboutToLoseControl()
- {
- if (IsShown() && IsHiddenOnSuspend())
- {
- fWasHiddenOnSuspend = TRUE;
- Boolean oldManageActivation = fGenerateActivates;
- fGenerateActivates = FALSE;
- Show(FALSE, kRedraw);
- fGenerateActivates = oldManageActivation;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::RegainControl:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::RegainControl()
- {
- if (fWasHiddenOnSuspend)
- {
- fWasHiddenOnSuspend = FALSE;
- // Any necessary activation is handled in TApplication.HandleSystemEvent
- Boolean oldManageActivation = fGenerateActivates;
- fGenerateActivates = FALSE;
- Show(TRUE, kRedraw);
- fGenerateActivates = oldManageActivation;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::Show:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::Show(Boolean state,
- Boolean redraw) // override
- {
- if (state)
- {
- // Be sure all views are sized right
- Resize(((CRect &)GetWindowPort(fWMgrWindow)->portRect).GetSize(), redraw);
- }
-
- if (fGenerateActivates && !fFloats)
- {
- if (state)
- MAShowWindow(fWMgrWindow);
- else
- MAHideWindow(fWMgrWindow);
- }
- else
- {
- if (fFloats)
- HiliteWindow(fWMgrWindow, state);
-
- ShowHide(fWMgrWindow, state);
- if (!state)
- Activate(FALSE); // at least de-activate ourselves when
- // hiding
- }
-
- // manage floaters window list position
- if (state && fFloats)
- {
- // if we are behind any of the normal document windows, we move
- // back into the floating layer
- CWMgrIterator iter;
- Boolean foundNormalDocWindow = FALSE;
- Boolean foundOurself = FALSE;
- Boolean needToMove = FALSE;
- for (WindowRef aWindowPtr = iter.FirstWMgrWindow(); iter.More(); aWindowPtr = iter.NextWMgrWindow())
- {
- if (aWindowPtr == fWMgrWindow)
- {
- foundOurself = TRUE;
- needToMove = foundNormalDocWindow;
- }
- else if (!IsModalWindow(aWindowPtr) && !IsFloatWindow(aWindowPtr))
- foundNormalDocWindow = TRUE;
- }
-
- if (needToMove)
- BringToFront(fWMgrWindow);
- }
-
- // manage activation:
- if (fFloats)
- Activate(state); // for floaters, activation == visibility
- else if ((!state) && IsActive())
- Activate(FALSE); // if active, de-activate ourselves when hiding
-
- Inherited::Show(state, redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::SimpleStagger:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TWindow::SimpleStagger(CPoint delta,
- short& counter)
- {
- fStaggered = TRUE;
- VRect theFrame(GetFrame());
-
- CRect moveBounds;
- GetDynamicMoveBounds(moveBounds);
-
- theFrame[botRight] = (theFrame[topLeft] + VPoint(moveBounds[botRight])) - theFrame[botRight];
-
- // This covers the case of delta.h && delta.v both >= 0; if either is less than 0, the
- // right (bottom) limit is set to the left (top) edge of the screen -- allowing for
- // some margin. This makes the right (bottom) edge less than the left (top) edge, but
- // this is OK since the/ statement below will be dividing 2 negative numbers.
-
- if (delta.h < 0)
- theFrame.right = fMoveBounds.left;
- if (delta.v < 0)
- theFrame.bottom = fMoveBounds.top;
-
- // This code avoids divide by zero problems
- short nSlots = (!delta.h || !delta.v) ? 0 : (short)Min((theFrame.GetLength(hSel) + delta.h - 1) / delta.h, (theFrame.GetLength(vSel) + delta.v - 1) / delta.v);//!!! long-> short
- short slot = nSlots ? counter % nSlots : 0;
-
- if (slot) // move the window
- {
- // The place to position the window
- Locate(theFrame[topLeft] + VPoint((slot * delta.h), (slot * delta.v)), kDontInvalidate);
- }
-
- ++counter;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::BeginUpdate:
- //----------------------------------------------------------------------------------------
- void TWindow::BeginUpdate()
- {
- fUpdating = TRUE; // So TWindow.Focus will know to focus TO
- // the update rgn
-
- //
- // Set the flags that let the GetVisibleRegion and GetUpdateRegion functions
- // return the correct regions.
- //
- pInBeginUpdate = TRUE;
- pInBeginUpdateWindowPtr = fWMgrWindow;
-
- //
- // Save the update region for reference, since ::BeginUpdate smashes it
- //
- if (!pSavedUpdateRegion)
- pSavedUpdateRegion = NewRgn();
- CopyRgn(((WindowPeek)fWMgrWindow)->updateRgn, pSavedUpdateRegion);
-
- // Yes, I know that there is an LMGetSaveVisRgn call available. The problem is that the Process Manager
- // doesn't [always?] switch the low memory global that stores the saved visRgn and that makes it
- // d*mn near impossible to debug-step through any framework updating code as the region
- // referenced there keeps getting modified. Copying the region to pSavedVisRegion is somewhat
- // less efficient... but actually works correctly.
- if (!pSavedVisRegion)
- pSavedVisRegion = NewRgn();
- CopyRgn(fWMgrWindow->visRgn, pSavedVisRegion);
-
- //
- // Save the offset of the visRgn since we'll need it in the GetVisRegion accessor function
- //
- RgnHandle savedVisRgn = pSavedVisRegion;
- pSavedVisRegionOriginalOffset = CPoint(((CRect &)(*savedVisRgn)->rgnBBox)[topLeft]) - ((CRect &)fWMgrWindow->portRect)[topLeft];
-
- ::BeginUpdate(fWMgrWindow);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::EndUpdate:
- //----------------------------------------------------------------------------------------
- void TWindow::EndUpdate()
- {
- fUpdating = FALSE;
-
- pInBeginUpdate = FALSE;
- pInBeginUpdateWindowPtr = NULL;
- SetEmptyRgn(pSavedUpdateRegion);
-
- SetEmptyRgn(pSavedVisRegion);
-
- ::EndUpdate(fWMgrWindow);
-
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::Update:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TWindow::Update() // override
- {
- // if we are already in the process of updating, don't do anything.
- if (!fUpdating)
- {
- if (HasPendingUpdate())
- {
- FailInfo fi;
- Try(fi)
- {
- InvalidateFocus();
- BeginUpdate();
- #if qDebug
- if (gShowInvalidations && Focus())
- {
- FillRect(&GetQDExtent(), &qd.ltGray);// we'll be clipped appropriately
- long finalTicks;
- Delay(15, &finalTicks); // so you can see it
- }
- #endif
-
- VRect updateVRect;
- RectToVRect((*GetUpdateRegion(fWMgrWindow))->rgnBBox, updateVRect);
- SuperToLocalVRect(updateVRect);
-
- HandleDraw(updateVRect);
-
- fi.Success();
- }
- else // Recover
- {
- // Or we get into an infinite loop
- // trying to update the window when
- // displaying an alert
- EndUpdate();
- InvalidateFocus();
-
- fi.ReSignal();
- }
-
- EndUpdate();
- InvalidateFocus();
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetStandardStateFrame: Former nested routine, now a private method
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::GetStandardStateFrame(const VRect& boundingRect,
- VRect& stdFrame)
- {
- const short edge = 2; // leave space around window structure area, settable?
- VPoint delta;
- VRect localBoundingRect = boundingRect;
-
- localBoundingRect.Inset(VPoint(edge, edge));
-
- // calculate the maximum structure size
- CRect resizeLimits;
- GetDynamicResizeLimits(resizeLimits);
-
- delta.h = Min((localBoundingRect.GetLength(hSel)), resizeLimits[botRight][hSel] + fContentDifference[hSel]);//!!! long-> short
- delta.v = Min((localBoundingRect.GetLength(vSel)), resizeLimits[botRight][vSel] + fContentDifference[vSel]);//!!! long-> short
-
- // Relocate the view only if necessary, and then move it as little as possible
- if ((fLocation.v >= localBoundingRect.top) && ((fLocation.v + delta.v - fContentDifference.v - 1) <= localBoundingRect.bottom))
- stdFrame.top = fLocation.v;
- else if (fLocation.v < localBoundingRect.top)
- stdFrame.top = localBoundingRect.top;
- else
- stdFrame.top = localBoundingRect.bottom - delta.v + fContentRegionInset.v;
- // stdFrame.top = localBoundingRect.top + fContentRegionInset.v + ((localBoundingRect.GetLength(vSel)) - delta.v) / 2;
-
- if ((fLocation.h >= localBoundingRect.left) && ((fLocation.h + delta.h - fContentDifference.h - 1) <= localBoundingRect.right))
- stdFrame.left = fLocation.h;
- else if (fLocation.h < localBoundingRect.left)
- stdFrame.left = localBoundingRect.left;
- else
- stdFrame.left = localBoundingRect.right - delta.h + fContentRegionInset.h;
- // stdFrame.left = localBoundingRect.left + fContentRegionInset.h + ((localBoundingRect.GetLength(hSel)) - delta.h) / 2;
-
- stdFrame[botRight] = stdFrame[topLeft] + delta - VPoint(fContentDifference) - VPoint(1, 1);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetUserStateFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::GetUserStateFrame(const VRect& /* boundingRect */ ,
- VRect& userFrame)
- {
- if (GetWindowZoomFlag(fWMgrWindow)) // has zoom box
- {
- CRect userQDState;
- GetWindowUserState(fWMgrWindow, &userQDState);
- userFrame = userQDState;
- }
- #if qDebug
- else
- ProgramBreak("Whoops");
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::Zoom:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::Zoom(short partCode)
- {
- CRect aGDScreenRect;
- VRect itsNewFrame;
-
- // Find out where the window would like to be zoomed out to
- GetMaxIntersectedDevice(aGDScreenRect);
- VRect aGDScreenVRect(aGDScreenRect);
-
- if (partCode == inZoomOut)
- {
- // new zoom-out CRect
- GetStandardStateFrame(aGDScreenVRect, itsNewFrame);
- if (GetWindowZoomFlag(fWMgrWindow)) // has zoom box
- {
- CRect newFrame = itsNewFrame.ToRect();
- SetWindowStandardState(fWMgrWindow, &newFrame);
- }
- }
- else
- { // new zoom-in CRect
- GetUserStateFrame(aGDScreenVRect, itsNewFrame);
- if (GetWindowZoomFlag(fWMgrWindow)) // has zoom box
- {
- CRect newFrame = itsNewFrame.ToRect();
- GetWindowUserState(fWMgrWindow, &newFrame);
- }
- }
-
- if (Focus()) // The ROM requires that thePort be the window being zoomed.
- {
- // if the window both moves and resizes then call the ZoomWindow trap to get the right visual
- // effect.
- // If it only moves OR resizes then just call SetFrame since more bits
- // may be preserved.
- if (itsNewFrame[topLeft] != fLocation && itsNewFrame.GetSize() != fSize)
- {
- EraseRect(&GetQDExtent());
-
- if (GetWindowZoomFlag(fWMgrWindow)) // check for a zoomable defproc
- ZoomWindow(fWMgrWindow, partCode, FALSE);
- }
-
- // let the View know what we've done
- SetFrame(itsNewFrame, kInvalidate);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::ZoomByUser:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::ZoomByUser(const VPoint& theMouse,
- short partCode)
- {
- VPoint globalVMouse(theMouse);
-
- LocalToSuper(globalVMouse);
- if (TrackBox(fWMgrWindow, globalVMouse.ToPoint(), partCode))
- {
- Zoom(partCode);
-
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn())
- {
- TSetPropertyEvent * theEvent = new TSetPropertyEvent;
- theEvent->ISetPropertyEvent(gServerAddress, kAENoReply + kAEDontExecute, this, pIsZoomed);
- theEvent->WriteBoolean(keyAEData, (partCode == inZoomOut));
- TAppleEvent * theReply = theEvent->Send();
- FreeIfObject(theEvent);
- FreeIfObject(theReply);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetDynamicMoveBounds:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TWindow::GetDynamicMoveBounds(CRect& moveBounds)
- {
- //
- // Any value is made dynamic by leaving it at zero. Any non-zero values
- // are honored.
- //
- moveBounds = fMoveBounds;
-
- CRect grayBox((*GetGrayRgn())->rgnBBox);
- grayBox.Inset(CPoint(4, 4));
-
- if (!fMoveBounds.top) // dynamic
- moveBounds.top = grayBox.top;
-
- if (!fMoveBounds.left) // dynamic
- moveBounds.left = grayBox.left;
-
- if (!fMoveBounds.bottom) // dynamic
- moveBounds.bottom = grayBox.bottom;
-
- if (!fMoveBounds.right) // dynamic
- moveBounds.right = grayBox.right;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetDynamicResizeLimits:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- void TWindow::GetDynamicResizeLimits(CRect& resizeLimits)
- {
- //
- // Any value in fResizeLimits is made dynamic by leaving it at zero. Any
- // non-zero values are honored.
- //
- resizeLimits = fResizeLimits;
-
- // maximum size vertically
- static const short kHalfTitleBar = 8;
- CPoint grayRgnBBoxSize(CRect((*GetGrayRgn())->rgnBBox).GetSize());
-
- if (!fResizeLimits.bottom) // dynamic
- resizeLimits.bottom = grayRgnBBoxSize.v - kHalfTitleBar;
-
- // maximum size horizontally
- if (!fResizeLimits.right) // dynamic
- resizeLimits.right = grayRgnBBoxSize.h;
-
- //
- // Ideally the window's settings should come from the window template and
- // the default settings should come from a resource (with a constant for a
- // backstop if the resource is not present). However, the template format
- // is not changing (for MA 3.3) and I'd have to check with the MacApp team
- // about defining a resource for the default.
- //
- // I am able to fix one persistent problem here, though. User interface
- // elements have been shrinking over the past several years and very small
- // status windows have become more common. MacApp has supplied a default
- // minimum resize limit of 80, 80 pixels in previous releases. This is too
- // large for these small windows and yet is still close to reasonable. I
- // propose to reduce the constant minimum to a slightly smaller value than
- // before (approximately two scroll arrows plus a thumb plus a resize icon)
- // as well as modifying the calculation of the default value to accept the
- // current size of the window as the minimum if it is smaller than the
- // constant values.
- //
- static const short kMinWindowWidth = kStdSzSBar * 4;
- static const short kMinWindowHeight = kStdSzSBar * 4;
-
- // minimum size vertically
- if (!fResizeLimits.top) // dynamic
- {
- resizeLimits.top = Min(kMinWindowHeight, resizeLimits.bottom);
- // capture the minimum if it will be smaller than the default
- if (fSize.v < resizeLimits.top)
- resizeLimits.top = fResizeLimits.top = fSize.v;
- }
-
- // minimum size horizontally
- if (!fResizeLimits.left) // dynamic
- {
- resizeLimits.left = Min(kMinWindowWidth, resizeLimits.right);
- // capture the minimum if it will be smaller than the default
- if (fSize.v < resizeLimits.left)
- resizeLimits.left = fResizeLimits.left = fSize.h;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetSpecifierForm:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- DescType TWindow::GetSpecifierForm()
- {
- CStr255 theName;
- GetTitle(theName);
-
- DescType theForm = (!theName.IsEmpty()) ? formName : MScriptableObject::GetSpecifierForm();
-
- return theForm;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::CountContainedObjects:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- long TWindow::CountContainedObjects(DescType desiredType)
- {
- long result = 0;
-
- if (IsShown() && !fFloats) // don't support floaters and invisible windows
- {
- if (gDispatcher->IsDocumentClass(desiredType))
- result = 1;
- else if (fDocument)
- result = fDocument->CountContainedObjects(desiredType);
- }
- else
-
- if (!result)
- result = MScriptableObject::CountContainedObjects(desiredType);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetCommandContext
- //----------------------------------------------------------------------------------------
- #pragma segment MAOSLDispatch
-
- TCommandHandler* TWindow::GetCommandContext(const CommandNumber/* aCommandNumber */ ) const
- {
- return fDocument ? (TCommandHandler*)fDocument : gDispatcher;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetContainedObject:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- MScriptableObject* TWindow::GetContainedObject(DescType desiredType,
- DescType selectionForm,
- const CAEDesc& selectionData)
- {
- MScriptableObject * result = NULL;
- if (IsShown() && !fFloats)
- {
- if (gDispatcher->IsDocumentClass(desiredType))
- result = fDocument;
- else if (fDocument && (desiredType != cProperty) && (desiredType != GetOMClass()))
- result = fDocument->GetContainedObject(desiredType, selectionForm, selectionData);
- }
-
- if (!result)
- result = MScriptableObject::GetContainedObject(desiredType, selectionForm, selectionData);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetObjectProperty:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- Boolean TWindow::GetObjectProperty(CAEDesc& thePropertyValue,
- DescType whichProperty,
- const CAEDesc& desiredType)
- {
- Boolean hasProperty = TRUE;
- FailInfo fi;
- Try(fi)
- {
- switch (whichProperty)
- {
- case pClass:
- thePropertyValue.PutType(GetOMClass());
- break;
-
- case pBounds:
- thePropertyValue.PutRect(ViewToQDRect(GetFrame()));
- break;
-
- case pName:
- {
- CStr255 theName;
- GetTitle(theName);
- thePropertyValue.PutString(theName);
- break;
- }
-
- case pHasCloseBox:
- thePropertyValue.PutBoolean(fIsClosable);
- break;
-
- case pHasTitleBar:
- thePropertyValue.PutBoolean(fContentDifference != gZeroPt);
- break;
-
- case pIndex:
- {
- CWMgrIterator iter;
- long index = 0;
- TWindow * aWindow = NULL;
- hasProperty = FALSE;
-
- for (WindowRef aWinPtr = iter.FirstWMgrWindow(); iter.More() && (aWindow != this); aWinPtr = iter.NextWMgrWindow())
- {
- aWindow = gDispatcher->WMgrToWindow(aWinPtr);
- // count its index either as a floater or non-floater
- if (aWindow && aWindow->IsShown() && (fFloats == aWindow->fFloats))
- {
- index++;
- if (aWindow == this)
- {
- thePropertyValue.PutLong(index);
- hasProperty = TRUE;
- }
- }
- }
- break;
- }
-
- case pIsModal:
- thePropertyValue.PutBoolean(IsModal());
- break;
-
- case pIsResizable:
- thePropertyValue.PutBoolean(fIsResizable);
- break;
-
- case pIsZoomable:
- thePropertyValue.PutBoolean((fProcID) & zoomDocProc);
- break;
-
- case pIsZoomed:
- {
- CRect aGDScreenRect;
- GetMaxIntersectedDevice(aGDScreenRect);
- VRect aGDScreenVRect(aGDScreenRect);
- VRect zoomFrame;
- GetUserStateFrame(aGDScreenVRect, zoomFrame);
- thePropertyValue.PutBoolean((GetFrame() != zoomFrame));
- break;
- }
-
- case pSelection:
- {
- TDocument * theDoc = fDocument;
- if (theDoc)
- {
- TDesignator * theUserSelection = theDoc->GetUserSelection();
- if (theUserSelection)
- {
- CTempDesc propData;
- theUserSelection->MakeObjectSpecifier(propData, theUserSelection->GetSpecifierForm());
- thePropertyValue = propData;
- }
- else
- FailOSErr(errAENoSuchObject);
- }
- break;
- }
-
- default:
- {
- // Users will frequently refer to the window when they mean the document. If this window
- // has a document we'll give it a crack at supplying the property.
- if (fDocument)
- hasProperty = fDocument->GetObjectProperty(thePropertyValue, whichProperty, desiredType);
- else
- hasProperty = MScriptableObject::GetObjectProperty(thePropertyValue, whichProperty, desiredType);
- }
- break;
- }
- fi.Success();
- }
- else // Recover
- {
- hasProperty = FALSE;
- }
- return hasProperty;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::GetSetPropertyInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::GetSetPropertyInfo(DescType whichProperty,
- CommandNumber& cmdNum,
- Boolean& canUndo,
- Boolean& causesChange,
- TCommandHandler*& theContext)
- {
- MScriptableObject::GetSetPropertyInfo(whichProperty, cmdNum, canUndo, causesChange, theContext);
-
- if (whichProperty == pBounds || whichProperty == pIsZoomed || whichProperty == pName)
- {
- canUndo = FALSE;
- causesChange = FALSE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::SetObjectProperty:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::SetObjectProperty(const CAEDesc& thePropertyValue,
- DescType whichProperty)
- {
- switch (whichProperty)
- {
- case pBounds:
- {
- CRect theWindowRect;
- thePropertyValue.GetRect(theWindowRect);
- SetFrame(VRect(theWindowRect), TRUE);
- }
- break;
-
- case pName:
- {
- CStr255 theWindowName;
- thePropertyValue.GetString(theWindowName);
- SetTitle(theWindowName);
- }
- break;
-
- case pIsZoomed:
- {
- CRect aGDScreenRect;
- GetMaxIntersectedDevice(aGDScreenRect);
- VRect aGDScreenVRect(aGDScreenRect);
- VRect zoomFrame;
- GetUserStateFrame(aGDScreenVRect, zoomFrame);
- Boolean isZoomed = (GetFrame() != zoomFrame);
- Boolean shouldZoom = thePropertyValue.GetBoolean();
- short partCode = 0;
- if (shouldZoom && !isZoomed)
- partCode = inZoomOut;
- else if (!shouldZoom && isZoomed)
- partCode = inZoomIn;
- if (partCode != 0)
- Zoom(partCode);
- break;
- }
-
- case pHasCloseBox:
- case pHasTitleBar:
- case pIsModal:
- case pIsResizable:
- case pIsZoomable:
- FailOSErr(errAECantSetReadOnly);
- break;
-
- default:
- // Users will frequently refer to the window when they mean the document. If this window
- // has a document we'll give it a crack at setting the property.
- if (fDocument)
- fDocument->SetObjectProperty(thePropertyValue, whichProperty);
- else
- MScriptableObject::SetObjectProperty(thePropertyValue, whichProperty);
- break;
- }
- }
-
- #if qAttachable
-
- //----------------------------------------------------------------------------------------
- // TWindow::HandleOSAEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
-
- Boolean TWindow::HandleOSAEvent(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply)
- {
- // Overridden to also give the document's script a shot at the event
- return MScriptableObject::HandleOSAEvent(aCommandNumber, message, reply) || (fDocument && fDocument->HandleOSAEvent(aCommandNumber, message, reply));
- }
-
- #endif // qAttachable
-
- //----------------------------------------------------------------------------------------
- // TWindow::DoAEMove:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::DoAEMove(TAppleEvent* message,
- TAppleEvent* reply)
- {
- CTempDesc theInsertionLoc, windowObj;
- CAEDesc insertionRec;
- DescType theType, position;
- Size paramSize;
- message->ReadParameter(keyAEInsertHere, typeInsertionLoc, theInsertionLoc);
- FailOSErr(AECoerceDesc(theInsertionLoc, typeAERecord, insertionRec));
- insertionRec.GetKeyDesc(keyAEObject, typeWildCard, windowObj);
- FailOSErr(AEGetKeyPtr(insertionRec, keyAEPosition, typeEnumeration, &theType, &position, sizeof(DescType), ¶mSize));
-
- if (position == kAEBeginning)
- Select(); // don't support the other keys yet
-
- FailOSErr(AEDisposeDesc(insertionRec));
-
- // Return an object specifier for the window
- CTempDesc theWindowSpec;
- MakeObjectSpecifier(theWindowSpec, formName);
- reply->WriteParameter(keyAEResult, theWindowSpec);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::DoAEClose:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::DoAEClose(TAppleEvent* message,
- TAppleEvent* reply)
- {
- // First see if a document is to be closed.
- if (fDocument && fClosesDocument)
- // Closing the document will close any associated windows.
- fDocument->DoAEClose(message, reply);
- else
- // Close the window if it wasn't attached to a document.
- DoClose(cClose, FALSE);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::DoAEPrint
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::DoAEPrint(TAppleEvent* message,
- TAppleEvent* reply)
- {
- Boolean wasHandled = FALSE;
-
- if (fScriptingPrintHandler)
- wasHandled = fScriptingPrintHandler->DoScriptCommand(cPrint, message, reply);
-
- if (!wasHandled)
- {
- if (fDocument)
- fDocument->HandleScriptCommand(cPrint, message, reply);
- else
- MScriptableObject::DoAEPrint(message, reply);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::DoScriptCommand
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::DoScriptCommand(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply)
- {
- switch (aCommandNumber)
- {
- case cAEDelete:
- DoAEClose(message, reply);
- break;
-
- case cAEOpen:
- case cAESave:
- case cAECountElements:
- case cAECreateElement:
- case cAEDoObjectsExist:
- if (fDocument)
- {
- fDocument->HandleScriptCommand(aCommandNumber, message, reply);
- break;
- }
- // no break - drop thru!
-
- default:
- MScriptableObject::DoScriptCommand(aCommandNumber, message, reply);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::SetScriptingPrintHandler
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::SetScriptingPrintHandler(TPrintHandler* printHandler)
- {
- fScriptingPrintHandler = printHandler;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::ReleaseScriptingPrintHandler
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::ReleaseScriptingPrintHandler(TPrintHandler* printHandler)
- {
- if (fScriptingPrintHandler == printHandler)
- fScriptingPrintHandler = NULL;
- }
-
- #if qDrag
-
- //----------------------------------------------------------------------------------------
- // Drag Support
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // TWindow::RegisterDroppableView
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TWindow::RegisterDroppableView(TView* theView)
- {
-
- #if qDebug
- if (!HasDragManager()) // should never get called if no Drag Manager
- {
- ProgramBreak("A TDragDropBehavior registered but the Drag Manager isn't present.");
- return;
- }
- #endif
-
- // the subview list isn't created until a view registers
- if (fDroppableViewList == NULL)
- {
- fDroppableViewList = new TList;
- fDroppableViewList->IList();
- #if qDebug
- fDroppableViewList->SetEltType("TView");
- #endif
-
- }
-
- #if qDebug
- ArrayIndex index = fDroppableViewList->GetIdentityItemNo(theView);
- if (index != 0)
- {
- // ProgramBreak("### A drag/drop view tried to register itself twice");
- return;
- }
- #endif
-
- fDroppableViewList->InsertElementInOrder(&theView);// add the view to the list
-
- // Register this window with the global drag session if appropriate
- if (fDragCallbackStatus == eNotInstalled)
- {
- TDragDropSession::fgDragDropSession->RegisterDroppableWindow(this, fWMgrWindow);
- fDragCallbackStatus = eInstalled;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::UnregisterDroppableView
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TWindow::UnregisterDroppableView(TView* theView)
- {
- #if qDebug
- if (!HasDragManager()) // should never get called if the Drag Mgr isn't present
- {
- ProgramBreak("###A drag/drop view unregistered but the Drag Manager is not present.");
- return;
- }
- FailNonObject(fDroppableViewList); // list shouldn't be NULL if this method is called
- #endif
-
- fDroppableViewList->Delete(theView);
-
- // if the behavior count went to zero, unregister the window callbacks
- if (fDroppableViewList->IsEmpty())
- {
- TDragDropSession::fgDragDropSession->UnregisterDroppableWindow(fWMgrWindow);
- fDragCallbackStatus = eNotInstalled;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::MouseToDropTarget
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TView* TWindow::MouseToDropTarget(CDragItemIterator& dragItemIterator,
- const CPoint& globalMouse,
- VPoint& localMouse)
- {
- TView * targetView = NULL;
- TView * aView = NULL;
- VPoint pointInWindow(globalMouse), aPoint;
- ArrayIndex maxIndex = fDropStatusCache->GetSize();
- short oldStatus,
- newStatus;
-
- SuperToLocal(pointInWindow);
-
- // Loop through the status list. The status list is a cache of values that
- // indicate whether or not a specific view can accept the drag.
- for (ArrayIndex index = 1; index <= maxIndex; index++)
- {
- fDropStatusCache->GetElementsAt(index, &oldStatus, 1);
- if (oldStatus != kCantReceiveDrop)
- {
- newStatus = oldStatus;
- fDroppableViewList->GetElementsAt(index, &aView, 1);
- if (newStatus == kDropStatusUnknown)
- {
- if (!aView->GetDroppable() || !aView->IsShown() || !aView->IsEnabled())
- newStatus = kCantReceiveDrop;
- }
-
- if (newStatus != kCantReceiveDrop)
- {
- aPoint = pointInWindow;
- aView->WindowToLocal(aPoint);
- if (aView->GetVisibleExtent().Contains(aPoint))
- {
- if (newStatus == kDropStatusUnknown)
- newStatus = aView->WillAcceptDrop(dragItemIterator) ? kCanReceiveDrop : kCantReceiveDrop;
-
- if ((newStatus == kCanReceiveDrop) && (!targetView || targetView->ContainsSubView(aView)))// we've got a winner!!
- {
- targetView = aView;
- localMouse = aPoint;
- }
- }
-
- }
- if (oldStatus != newStatus)
- fDropStatusCache->ReplaceElementsAt(index, &newStatus, 1);// cache the new status
- }
- }
-
- return targetView;
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::DragEnteredWindow
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TWindow::DragEnteredWindow(CDragItemIterator&/* dragItemIterator */ )
- {
-
- #if qDebug
- FailNonObject(fDroppableViewList); // list shouldn't be NULL if this method is called
- #endif
-
- short viewStatus = kDropStatusUnknown;
- ArrayIndex viewListSize = fDroppableViewList->GetSize();
-
- fDropStatusCache = new TDynamicArray;
- fDropStatusCache->IDynamicArray(viewListSize, sizeof(short));
-
- // initialize the status list with kDropStatusUnknown
- for (ArrayIndex i = 0; i < viewListSize; i++)
- fDropStatusCache->InsertElementsBefore(i + 1, &viewStatus, 1);
- }
-
- //----------------------------------------------------------------------------------------
- // TWindow::DragLeftWindow
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TWindow::DragLeftWindow()
- {
- fDropStatusCache = (TDynamicArray *)FreeIfObject(fDropStatusCache);
- }
-
- #endif // qDrag
-
- //----------------------------------------------------------------------------------------
- // GetVisRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- RgnHandle TWindow::GetVisRegion(GrafPtr theGrafPtr)
- {
- RgnHandle returnVal;
-
- if (pInBeginUpdate && theGrafPtr == pInBeginUpdateWindowPtr)
- {
- returnVal = pSavedVisRegion;
-
- CPoint currentOffset(((CRect &)(*returnVal)->rgnBBox)[topLeft]);
- OffsetRgn(returnVal, -currentOffset.h + theGrafPtr->portRect.left + pSavedVisRegionOriginalOffset.h, -currentOffset.v + theGrafPtr->portRect.top + pSavedVisRegionOriginalOffset.v);
- }
- else
- returnVal = theGrafPtr->visRgn;
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // GetUpdateRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- RgnHandle TWindow::GetUpdateRegion(WindowPtr theWindow)
- {
- RgnHandle returnVal;
-
- if (TWindow::pInBeginUpdate && theWindow == pInBeginUpdateWindowPtr)
- returnVal = pSavedUpdateRegion;
- else
- returnVal = ((WindowPeek)theWindow)->updateRgn;
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // GetAndLoadWDefProc:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- Handle TWindow::GetAndLoadWDefProc(Handle windowDefProc)
- {
- Handle returnVal = NULL;
- Handle wDefProc = (Handle)(StripLong(windowDefProc));// strip the variant code
-
- if ((*wDefProc)) // if Master Ptr is NULL => resource is purged
- returnVal = wDefProc;
- else
- {
- LoadResource(wDefProc);
- if (ResError() == noErr) // only return it if the LoadResource worked
- returnVal = wDefProc;
- }
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // HighlightAndActivateWindow: Common code for ActivateWindow and DeactivateWindow. Does
- // actual highlighting and calling of the activate handler.
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::HighlightAndActivateWindow(WindowRef theWindow,
- Boolean activate)
- {
- if (theWindow)
- {
- if ((activate && !IsWindowHilited(theWindow)) || (!activate && IsWindowHilited(theWindow)))
- HiliteWindow(theWindow, activate); // make the window "look" right
-
- TWindow * theMAWindow = WMgrToWindow(theWindow);
- if (theMAWindow)
- theMAWindow->Activate(activate);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // IsGhostWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::IsGhostWindow(WindowRef window)
- {
- Boolean returnVal = FALSE;
-
- #if !STRICT_WINDOWS
- if (window)
- returnVal = window == (WindowRef)LMGetGhostWindow();
- #endif
-
- return returnVal;
- }
-
-
- //----------------------------------------------------------------------------------------
- // WMgrToWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- TWindow* TWindow::WMgrToWindow(WindowRef aWindowPtr)
- {
- if (gWindows)
- {
- CArrayIterator iter(gWindows);
-
- // simple linear search for now
- for (ArrayIndex i = iter.FirstIndex(); iter.More(); i = iter.NextIndex())
- {
- WMgrTWindowPtr aWMgrTWindowPtr = (WMgrTWindowPtr)gWindows->ComputeAddress(i);
-
- if (aWMgrTWindowPtr->itsWindow == aWindowPtr)
- return aWMgrTWindowPtr->itsTWindow;
- }
- }
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // DeleteWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::DeleteWindow(TWindow* aWindow)
- {
- if (gWindows)
- {
- CArrayIterator iter(gWindows);
-
- // simple linear search for now
- for (ArrayIndex i = iter.FirstIndex(); iter.More(); i = iter.NextIndex())
- {
- if (aWindow == ((WMgrTWindowPtr)(gWindows->ComputeAddress(i)))->itsTWindow)
- {
- gWindows->DeleteElementsAt(i, 1);
- return;
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // RegisterWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::RegisterWindow(TWindow* aWindow)
- {
- if (!gWindows)
- {
- gWindows = new TDynamicArray;
- gWindows->IDynamicArray(kEmptyIndex, sizeof(WMgrTWindow));
- }
-
- WMgrTWindow itsWMgrTWindow;
- itsWMgrTWindow.itsTWindow = aWindow;
- itsWMgrTWindow.itsWindow = aWindow->fWMgrWindow;
-
- gWindows->InsertElementsBefore(gWindows->GetSize() + 1, &itsWMgrTWindow, 1);
- }
-
- //----------------------------------------------------------------------------------------
- // IsDocumentWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- Boolean TWindow::IsDocumentWindow(WindowRef aWindow)
- // If a window is not a floater window, and is not a system window, and is not the special
- // THINK environment window, then it is a document window.
- {
- const short kTHINKWindowKind = 32700;
- short itsWindowKind;
-
- itsWindowKind = GetWindowKind(aWindow);
- return (!IsFloatWindow(aWindow) && !IsSystemWindow(aWindow) && (itsWindowKind < kTHINKWindowKind));
- }
-
- //----------------------------------------------------------------------------------------
- // IsDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::IsDialog(WindowRef window)
- {
- if (window)
- {
- // When checking the window type mask off all but the
- // bottom 3 bits, which is all we care about.
- short windowVariant = (GetWindowVariant(window) & 7);
- return (windowVariant == dBoxProc) || (windowVariant == plainDBox) || (windowVariant == altDBoxProc) || (windowVariant == movableDBoxProc);
- }
- else
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // IsFloatWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::IsFloatWindow(WindowRef window)
- {
- // A note on IsFloatWindow:
- // We only consider a window to be a floating window if it is visible.
- // The motivation around the check for visibility is that, given the Toolbox
- // Window Manager's tendency to move visible windows to the head of WindowList,
- // there is no clean way for us to guarantee that hidden floaters will stay in
- // our floating window "layer". Instead, the approach we take is to allow
- // hidden floaters to be moved wherever in the window list, and we ensure that
- // they move back to the floating window layer when they are shown. The check
- // for visibility ensures that functions that depend on the first or last
- // floating window (such as TWindow::GetBehindWindowPtr) perform as expected.
- Boolean returnVal = FALSE;
-
- if (window && IsWindowVisible(window))
- {
- TWindow * aMAWindow = WMgrToWindow(window);
- if (aMAWindow)
- returnVal = aMAWindow->fFloats;
- else
- returnVal = GetWindowKind(window) == kFloatingWindowKind;
- }
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // IsSystemWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::IsSystemWindow(WindowRef window)
- {
- Boolean returnVal = FALSE;
-
- const short kWorldScriptWDEF = 125;
- if (window)
- {
- short theID;
- ResType theType;
- CStr255 theName;
- GetResInfo(((WindowPeek)window)->windowDefProc, &theID, &theType, theName);
- short windowKind = GetWindowKind(window);
- returnVal = (windowKind < 0) || (theID == kWorldScriptWDEF) || (theID == kBalloonWDEFID);
- }
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // IsModalWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- Boolean TWindow::IsModalWindow(WindowRef window)
- {
- TWindow * aMAWindow = NULL;
- Boolean result = FALSE;
-
- if (window)
- {
- if ((aMAWindow = WMgrToWindow(window)) != NULL)
- result = aMAWindow->IsModal();
- else
- {
- // according to IM 4-9 (new version), these are
- // the possible window variants for modal dialogs:
- short windowVariant = GetWindowVariant(window);
- result = (windowVariant == dBoxProc) || (windowVariant == plainDBox) || (windowVariant == altDBoxProc) || (windowVariant == movableDBoxProc);
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // GetLastFloatingWindowPtr:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- // returns the last floating window in the window list
- WindowRef TWindow::GetLastFloatingWindowPtr()
- {
- CWMgrIterator iter;
- WindowRef lastFloatWindowPtr = NULL;
-
- for (WindowRef aWindowPtr = iter.FirstWMgrWindow(); iter.More(); aWindowPtr = iter.NextWMgrWindow())
- {
- if (IsFloatWindow(aWindowPtr))
- lastFloatWindowPtr = aWindowPtr;
- }
-
- return lastFloatWindowPtr;
- }
-
- //----------------------------------------------------------------------------------------
- // GetFirstFloatingWindowPtr:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- // returns the first floating window in the window list
- WindowRef TWindow::GetFirstFloatingWindowPtr()
- {
- CWMgrIterator iter;
- WindowRef firstFloatWindowPtr = NULL;
-
- for (WindowRef aWindowPtr = iter.FirstWMgrWindow(); iter.More() && (firstFloatWindowPtr == NULL); aWindowPtr = iter.NextWMgrWindow())
- {
- if (IsFloatWindow(aWindowPtr))
- firstFloatWindowPtr = aWindowPtr;
- }
-
- return firstFloatWindowPtr;
- }
-
- //----------------------------------------------------------------------------------------
- // ActivateWindow: Activates the window by highlighting it, and calling its
- // activate handler.
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::MAActivateWindow(WindowRef theWindow)
- {
- HighlightAndActivateWindow(theWindow, kActivateWindow);
- }
-
- //----------------------------------------------------------------------------------------
- // DeactivateWindow: Deactivates the window by unhighlighting it and calling its
- // activate handler.
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::MADeactivateWindow(WindowRef theWindow)
- {
- HighlightAndActivateWindow(theWindow, kDeactivateWindow);
- }
-
- //----------------------------------------------------------------------------------------
- // MADragWindow: Our replacement for DrawWindow to handle floating windows…
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::MADragWindow(WindowRef windowToDrag,
- CPoint startPoint,
- const CRect& draggingBounds)
- {
- CRect dragRect;
- GrafPtr savePort;
- GrafPtr windowManagerPort;
- long dragResult;
- short topLimit;
- short newHorizontalWindowPosition;
- short newVerticalWindowPosition;
- short horizontalOffset;
- short verticalOffset;
- Boolean commandKeyDown = FALSE;
-
- if (WaitMouseUp())
- {
- // Adjust the top of the dragging rectangle so that it’s below the menu bar
- topLimit = GetMBarHeight() + 4;
- dragRect = draggingBounds;
- if (dragRect.top < topLimit)
- dragRect.top = topLimit;
-
- // Set up the Window Manager port.
- GetPort(&savePort);
- GetWMgrPort(&windowManagerPort);
- SetPort(windowManagerPort);
- SetClip(GetGrayRgn());
-
- commandKeyDown = IsCommandKeyDown();
-
- if (commandKeyDown || !(IsFloatWindow(windowToDrag) || IsModalWindow(windowToDrag)))
- {
- if (!commandKeyDown)
- {
- // If there are floating windows, clip the dragging outline to draw
- // behind the floaters.
- ClipAbove(MAFrontWindow());
- }
- else
- {
- // If the command key was down, clip the outline to draw behind any
- // windows above the window being dragged.
- ClipAbove(windowToDrag);
- }
- }
-
- // Create a region to drag
- CTemporaryRegion dragRegion;
-
- GetWindowStructureRgn(windowToDrag, dragRegion);
-
- // Drag the window around
- dragResult = DragGrayRgn(dragRegion, startPoint, &dragRect, &dragRect, noConstraint, NULL);
-
- // Restore the port for coordinate conversion.
- SetPort(savePort);
-
- if (dragResult != 0)
- {
- horizontalOffset = (short)(dragResult & 0xFFFF);
- verticalOffset = (short)(dragResult >> 16);
-
- // Only move it if it stayed inside the dragging box.
- if (verticalOffset != -32768)
- {
- CTemporaryRegion contRgn;
- GetWindowContentRgn(windowToDrag, contRgn);
-
- newHorizontalWindowPosition = (*contRgn)->rgnBBox.left + horizontalOffset;
- newVerticalWindowPosition = (*contRgn)->rgnBBox.top + verticalOffset;
-
- MoveWindow(windowToDrag, newHorizontalWindowPosition, newVerticalWindowPosition, FALSE);
- }
- }
-
- // Bring the window forward if the command key wasn’t down
- if (!commandKeyDown)
- MASelectToolboxWindow(windowToDrag);// 3.5
- }
- }
-
- // Added for 3.5:
- //----------------------------------------------------------------------------------------
- // MASelectToolboxWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- void TWindow::MASelectToolboxWindow(WindowRef windowToSelect)
- {
- WindowRef currentFrontWindow = NULL;
- WindowRef lastFloatingWindow = NULL;
- Boolean isFloatingWindow = IsFloatWindow(windowToSelect);
-
- if (isFloatingWindow)
- {
- currentFrontWindow = GetFirstFloatingWindowPtr();
- }
- else
- {
- currentFrontWindow = MAFrontWindow();
- lastFloatingWindow = GetLastFloatingWindowPtr();
- }
-
- // Be fast (and lazy) and do nothing if we don’t have to.
- if (currentFrontWindow != windowToSelect)
- {
- // Selecting floating windows are easy, since they’re always active
- if (isFloatingWindow)
- BringToFront(windowToSelect);
- else
- {
- // If there are no floating windows, we can call SelectWindow like the good ol’ days
- if (lastFloatingWindow == NULL)
- {
- //SRF
- // Keep control off Window's control list b/c the Window Mgr adds the regions of controls in
- // the control list to the update region (see NOTE under DrawControls in Inside Mac volume I)
- // generating an update event and causing all controls in a window to redraw unnecessarily.
-
- ControlHandle oldFrontControlList;
- ControlHandle newFrontControlList;
- #if STRICT_WINDOWS
- if (currentFrontWindow)
- {
- oldFrontControlList = GetControlOwningWindowControlList(currentFrontWindow);
- GetControlOwningWindowControlList(currentFrontWindow) = NULL;
- }
-
- newFrontControlList = GetControlOwningWindowControlList(windowToSelect);
- GetControlOwningWindowControlList(windowToSelect) = NULL;
- #else
- if (currentFrontWindow)
- {
- oldFrontControlList = ((WindowPeek)currentFrontWindow)->controlList;
- ((WindowPeek)currentFrontWindow)->controlList = NULL;
- }
-
- newFrontControlList = ((WindowPeek)windowToSelect)->controlList;
- ((WindowPeek)windowToSelect)->controlList = NULL;
- #endif
-
- SelectWindow(windowToSelect);
-
- #if STRICT_WINDOWS
- if (currentFrontWindow)
- GetControlOwningWindowControlList(currentFrontWindow) = oldFrontControlList;
-
- GetControlOwningWindowControlList(windowToSelect) = newFrontControlList;
- #else
- if (currentFrontWindow)
- ((WindowPeek)currentFrontWindow)->controlList = oldFrontControlList;
-
- ((WindowPeek)windowToSelect)->controlList = newFrontControlList;
- #endif
-
- }
- else
- {
- // Deactivate the window currently in front.
- MADeactivateWindow(currentFrontWindow);
-
- // Bring it behind the last floating window if it is not modal and activate it.
- // Note that Inside Mac 1 states that you need to call PaintOne() and CalcVis() on a
- // window if you are using SendBehind() to bring it closer to the front. With System 7,
- // this is no longer necessary.
-
- if (!(IsModalWindow(windowToSelect)))
- SendBehind(windowToSelect, lastFloatingWindow);
- else
- BringToFront(windowToSelect);
-
- MAActivateWindow(windowToSelect);
- }
- }
- }
-
- // Make sure previous mouse clicks are not considered part of a multi-click.
- gDispatcher->fLastClickPart = inDesk;
- }
- // End added for 3.5
-
- //----------------------------------------------------------------------------------------
- // MAShowWindow: Show the specified window. If the window is the frontmost document
- // window, unhighlight the window behind it, deactivate it, and activate this one.
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::MAShowWindow(WindowRef windowToShow)
- {
- enum WindowFoundState
- {
- eWindowNotFound, eWindowIsFrontmost, eWindowIsNotFrontmost
- };
-
-
- WindowRef frontNonFloatingNonModalWindow = NULL;
- Boolean windowIsInFront = FALSE;
-
- if (!IsWindowVisible(windowToShow))
- {
- frontNonFloatingNonModalWindow = MAFrontWindow();
-
- if (IsFloatWindow(windowToShow))
- {
- // A floating window is being shown. Check to see if a modal window is up before
- // allowing the floater to receive activates.
- windowIsInFront = !IsModalWindow(FrontWindow());
- }
- else
- {
- if (IsModalWindow(windowToShow))
- {
- // We are bringing up a modal window! If we are bringing it up in front of
- // another modal window, we need to deactivate that one. Otherwise we need
- // to make sure that the frontNonFloatingNonModalWindow has been deactivated…
- CWMgrIterator iter;
- WindowFoundState windowToShowFoundState = eWindowNotFound;
-
- for (WindowRef aWindowPtr = iter.FirstWMgrWindow(); iter.More() && (windowToShowFoundState == eWindowNotFound); aWindowPtr = iter.NextWMgrWindow())
- {
- if (aWindowPtr == windowToShow)
- windowToShowFoundState = eWindowIsFrontmost;
- else if (IsWindowVisible(aWindowPtr))
- windowToShowFoundState = (IsModalWindow(aWindowPtr) ? eWindowIsNotFrontmost : eWindowIsFrontmost);
- }
-
- if (windowToShowFoundState == eWindowIsFrontmost)
- {
- windowIsInFront = TRUE;
-
- // now deactivate the frontmost modal window or nonfloater, whichever comes first…
- WindowRef theWnd = FrontWindow();
- if (theWnd)
- {
- if (IsModalWindow(theWnd))
- MADeactivateWindow(theWnd);
- else
- MADeactivateWindow(frontNonFloatingNonModalWindow);
- }
- }
- }
- else
- {
- // We are showing a non-floater, non-modal window. If it is in front of the
- // frontNonFloatingNonModalWindow, we need a deactivate…
-
- if (frontNonFloatingNonModalWindow == NULL)
- windowIsInFront = TRUE;
- else
- {
- CWMgrIterator iter;
- WindowFoundState windowToShowFoundState = eWindowNotFound;
-
- for (WindowRef aWindowPtr = iter.FirstWMgrWindow(); iter.More() && (windowToShowFoundState == eWindowNotFound); aWindowPtr = iter.NextWMgrWindow())
- {
- if (aWindowPtr == windowToShow)
- windowToShowFoundState = eWindowIsFrontmost;
- else if (aWindowPtr == frontNonFloatingNonModalWindow)
- windowToShowFoundState = eWindowIsNotFrontmost;
- }
-
- if (windowToShowFoundState == eWindowIsFrontmost)
- {
- windowIsInFront = TRUE;
- MADeactivateWindow(frontNonFloatingNonModalWindow);
- }
- }
- }
- }
-
- if (windowIsInFront || IsFloatWindow(windowToShow))
- {
- // Set the highlight state so the window appears highlighted from the start.
- HiliteWindow(windowToShow, TRUE);
- }
-
- // Show the window
- ShowHide(windowToShow, TRUE);
-
- // If this is the new frontmost document window or a floating window, send it an activate event
- if (windowIsInFront)
- {
- TWindow * theMAWindow = NULL;
- if ((theMAWindow = WMgrToWindow(windowToShow)) != NULL)
- {
- theMAWindow->Activate(TRUE);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // MAHideWindow: Hide the specified window.
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowNonRes
-
- void TWindow::MAHideWindow(WindowRef windowToHide)
- {
- Boolean needToActivateAnotherWindow = FALSE;
-
- // Don’t do anything if the window is already invisible.
- if (IsWindowVisible(windowToHide))
- {
- needToActivateAnotherWindow = IsWindowHilited(windowToHide) && !IsFloatWindow(windowToHide);
-
- // Give the window a change of deactivating in case it is presently active…
- MADeactivateWindow(windowToHide);
-
- // Hide the window.
- ShowHide(windowToHide, FALSE);
-
- // if we were hiding the active window (it was either the frontmost nonfloater or the
- // frontmost modal window), we need to find and activate another window…
- if (needToActivateAnotherWindow)
- {
- WindowRef windowToActivate = FrontWindow();
- while (windowToActivate && (IsFloatWindow(windowToActivate) || !IsWindowVisible(windowToActivate)))
- windowToActivate = GetNextWindow(windowToActivate);
-
- // if we found one, activate it!
- if (windowToActivate != NULL)
- MAActivateWindow(windowToActivate);
- }
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // MAFrontWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- // Returns the first visible, non-floater window in the window list. Ignores the ghost window (if any).
- // Note that if a modal window has been brought up in front of the floaters, we bypass it too.
- WindowRef TWindow::MAFrontWindow()
- {
- WindowRef returnVal = NULL;
-
- CWMgrIterator iter;
-
- for (WindowRef aWindowPtr = iter.FirstWMgrWindow(); iter.More(); aWindowPtr = iter.NextWMgrWindow())
- {
- if (!(IsFloatWindow(aWindowPtr) || IsGhostWindow(aWindowPtr) || IsSystemWindow(aWindowPtr) || IsModalWindow(aWindowPtr)) && IsWindowVisible(aWindowPtr))
- {
- returnVal = aWindowPtr;
- break;
- }
- }
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // FreeIfWMgrWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- WindowRef TWindow::FreeIfWMgrWindow(WindowRef w,
- Boolean dispose)
- {
- if (w)
- {
- // If the window is visible, hide it first so
- // that the proper activate and deactivate events are sent.
- if (IsWindowVisible(w))
- MAHideWindow(w);
-
- if (dispose)
- {
- if (GetWindowPort(w) == (CGrafPtr)qd.thePort)// Only need to invalidate focus if freed window is the current port
- {
- if (gDispatcher)
- gDispatcher->InvalidateFocus();
- SetPortWindowPort(gWorkPort);
- }
- DisposeWindow(w);
- }
- else
- CloseWindow(w);
- }
- return NULL; // convenience to caller
- }
-
- //----------------------------------------------------------------------------------------
- // End of UWindow.cp
-
- #pragma segment Inline
-
-